@chaingpt/nft
v0.0.8
Published
SDK for Nft
Downloads
249
Readme
ChainGPT AI NFT SDK
This library provides convenient access to the ChainGPT AI NFT REST API from TypeScript or JavaScript.
Installation
npm install --save @chaingpt/nft
# or
yarn add @chaingpt/nft
Usage
Generate an image
const { Nft } = require('@chaingpt/nft');
const fs = require('fs');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const generatedImage = await nftInstance.generateImage({
prompt: 'cars racing to the finish', // Prompt to be used to generate the NFT art
model: 'velogen', // Model to be used to generate the NFT art
enhance: 'original', // enhance imgae once or twice
steps: 2, // steps parameter passed while image generation
height: 512, //height of the resulting image
width: 512, // width of the resulting image
style: 'cinematic', //sample value for style
traits: [
//optional traits
{
trait_type: 'Background',
value: [
{ value: 'Heaven', ratio: 20 },
{ value: 'Hell', ratio: 60 },
{ value: 'Pakistan', ratio: 20 },
],
},
{
trait_type: 'contrast',
value: [
{ value: 'dark', ratio: 20 },
{ value: 'light', ratio: 80 },
],
},
],
});
// Save the buffer directly to a file
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Generate an image using Dale3
const { Nft } = require('@chaingpt/nft');
const fs = require('fs');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const generatedImage = await nftInstance.generateImage({
prompt: 'cars racing to the finish', // Prompt to be used to generate the NFT art
model: 'Dale3', // Model to be used to generate the NFT art
upscale: true, // enhance imgae
height: 1024, //height of the resulting image
width: 1024, // width of the resulting image
style: 'cinematic', //sample value for style
traits: [
//optional traits
{
trait_type: 'Background',
value: [
{ value: 'Heaven', ratio: 20 },
{ value: 'Hell', ratio: 60 },
{ value: 'Pakistan', ratio: 20 },
],
},
{
trait_type: 'contrast',
value: [
{ value: 'dark', ratio: 20 },
{ value: 'light', ratio: 80 },
],
},
],
});
// Save the buffer directly to a file
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
get chains to generate NFT on a chain, to get testNet chains aswell pass true as parameter
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const chains = await nftInstance.getChains(false); // true for testnet
console.log(chains);
}
main();
Generate an NFT
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const generatedNFT = await nftInstance.generateNft({
walletAddress: '<your wallet address>', // Public Key of the wallet that will mint NFT
prompt: 'a car being modified', // Prompt to be used to generate the NFT art
model: 'velogen', // Model to be used to generate the NFT art
enhance: '1x', // enhance imgae once or twice
steps: 3, // steps parameter passed while image generation
height: 1024, //height of the resulting image
width: 1024, // width of the resulting image
chainId: 97, //chain id
amount: 1, // no of images to generate
style: 'cinematic', //sample value for style
traits: [
{
trait_type: 'contrast', // set trait name
value: [
// set ratio for values
{ value: 'dark', ratio: 20 },
{ value: 'light', ratio: 80 },
],
},
],
});
console.log(generatedNFT);
}
main();
Generate an NFT and queue the generation instead of waiting for it to complete
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const generatedNFTQueue = await nftInstance.generateNftWithQueue({
walletAddress: '<your wallet address>', // Public Key of the wallet that will mint NFT
prompt: 'dragon', // Prompt to be used to generate the NFT art
model: 'Dale3', // Model to be used to generate the NFT art
upscale: true, // upscale imgae
height: 1024, //height of the resulting image
width: 1024, // width of the resulting image
chainId: 56, //chain id
amount: 2, //no of images to generate
style: 'cinematic', //sample value for style
traits: [
{
trait_type: 'contrast', // set trait name
value: [
// set ratio for values
{ value: 'dark', ratio: 20 },
{ value: 'light', ratio: 80 },
],
},
],
});
console.log(generatedNFTQueue);
}
main();
Check the creation progress of your NFT Generation (useful with generateNftWithQueue()
)
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const getProgress = await nftInstance.getNftProgress({
collectionId: '<collection id>', // your NFT generation collection ID
});
console.log(getProgress);
}
main();
Enhances your prompt by adding more details and context to improve image generation quality.
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const enhancedPrompt = await nftInstance.enhancePrompt({
prompt: 'lion in jungle',
});
console.log(enhancedPrompt);
}
main();
Generate a random prompt for NFT creation
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const randomPrompt = await nftInstance.surpriseMe();
// Returns a randomly generated prompt that can be used for NFT creation
console.log(randomPrompt);
}
main();
Get collections generated by your api key with optional filters
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const collections = await nftInstance.getCollections({
walletAddress: '<wallet address>', // Wallet address to filter collections
isPublic: true, // Filter by public status
// isDraft: false, // Filter by draft status (addtional filter)
// isMinted: false, // Filter by minted status (addtional filter)
// name: "<name>", // Filter by collection name (addtional filter)
// symbol: "<symbol>", // Filter by collection symbol (addtional filter)
page: 1, // Page number for pagination
limit: 10, // Number of items per page
});
}
main();
Toggle NFT visibility (make public/private)
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const response = await nftInstance.toggleNftVisibility({
collectionId: '<collection id>', // ID of the collection to toggle visibility
});
console.log(response);
}
main();
Retrieving required data to mint the generated NFT
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const mint = await nftInstance.mintNft({
collectionId: '<collection Id>', // Your NFT generation Collection ID
ids: [1], // collection to mint from generated images starting from 1
name: '<name>', // A name for your NFT
description: '<description>', // A description for your NFT
symbol: '<symbol>', // symbol
});
console.log(mint);
}
main();
Retrieving the NFT Mint Factory Contract ABI to call the Mint function
const { Nft } = require('@chaingpt/nft');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const abi = await nftInstance.abi();
console.log(abi);
}
main();
Supported Models
Here is a list of supported models:
- velogen
- nebula_forge_xl
- VisionaryForge
- Dale3
Enhance Image
You can enhance you image once or twice by using enhance property
- for enhancement pass enhance ='1x'
- for double enhancement pass enhance ='2x'
Models that support enhancement:
- velogen
- nebula_forge_xl
- VisionaryForge
Steps
Steps property can be used to refine image verious times.
- velogen supports steps 1 to 4 with default 2
- nebula_forge_xl supports steps to 50 with default 25
Supported Resolutions (Height/Width)
Each model supports specific resolutions for optimal results.
Velogen
Without Enhancement
- Square: 512×512
- Landscape: 768×512
- Portrait: 512×768
With Enhancement
- Square: 1920×1920
- Landscape: 1920×1280
- Portrait: 1280×1920
Nebula Forge XL
Base Resolutions
- Square: 1024×1024
- Landscape: 1024×768
- Portrait: 768×1024
Upscaled Resolutions
- Square: 1536×1536
- Landscape: 1536×1024
- Portrait: 1024×1536
VisionaryForge
Base Resolutions
- Square: 1024×1024
- Landscape: 1024×768
- Portrait: 768×1024
Upscaled Resolutions
- Square: 1536×1536
- Landscape: 1536×1024
- Portrait: 1024×1536
Supported Styles
Here is a list of supported models:
- 3d-model
- analog-film
- anime
- cinematic
- comic-book
- digital-art
- enhance
- fantasy-art
- isometric
- line-art
- low-poly
- neon-punk
- origami
- photographic
- pixel-art
- texture
- craft-clay
Handling errors
When the library is unable to connect to the API,
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
an error of the class NftError
will be thrown:
import { Errors } from '@chaingpt/nft';
async function main() {
try {
const response = await nftInstance.abi();
console.log(response.data);
} catch (error) {
if (error instanceof Errors.NftError) {
console.log(error.message);
}
}
}
main();