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
yarn add @chaingpt/nft
Usage
Generate a text to image using Velogen
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',
model: 'velogen',
enhance: 'original',
steps: 2,
height: 512,
width: 512,
style: 'cinematic',
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Generate an image to image using Velogen
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: "medieval fantasy knight, wearing armor",
image: "https://chaingpt.s3.dualstack.us-east-2.amazonaws.com/sdk/cgpt-bot.jpg",
model: 'velogen',
enhance: 'original',
steps: 3,
height: 1024,
width: 1024,
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Generate a text to image using nebula forge
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',
model: 'nebula_forge_xl',
enhance: 'original',
steps: 25,
height: 1024,
width: 1024,
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Generate an image to image using nebula forge
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: "medieval fantasy knight, wearing armor",
image: "https://chaingpt.s3.dualstack.us-east-2.amazonaws.com/sdk/cgpt-bot.jpg",
model: 'nebula_forge_xl',
enhance: 'original',
steps: 20,
height: 1024,
width: 1024,
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Generate a text to image using visionary forge
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, realistic and higly detailed image',
model: 'VisionaryForge',
enhance: 'original',
height: 1024,
width: 1024,
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Generate an image to image using visionary forge
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: "medieval fantasy knight, wearing armor",
image: "https://chaingpt.s3.dualstack.us-east-2.amazonaws.com/sdk/cgpt-bot.jpg",
model: 'VisionaryForge',
enhance: 'original',
height: 1024,
width: 1024,
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Character Reference NFT Image Generation
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: "musician playing guitar under stage lights",
image: "https://chaingpt.s3.dualstack.us-east-2.amazonaws.com/sdk/cgpt-bot.jpg",
model: 'velogen',
enhance: 'original',
steps: 3,
height: 1024,
width: 1024,
isCharacterPreserve: true
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Note: If isCharacterPreserve is set to true, you must also provide a valid image URL.
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',
model: 'Dale3',
upscale: true,
height: 1024,
width: 1024,
style: 'cinematic',
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 },
],
},
],
});
fs.writeFileSync('generated-image.jpg', Buffer.from(generatedImage.data.data));
}
main();
Multiple NFT Images Generation
const { Nft } = require('@chaingpt/nft');
const fs = require('fs');
const nftInstance = new Nft({
apiKey: 'Your ChainGPT API Key',
});
async function main() {
const generatedImages = await nftInstance.generateMultipleImages({
prompt: [
'cars racing to the finish',
'bot running in the jungle'
],
model: 'velogen',
enhance: '1x',
steps: 2,
height: 512,
width: 512,
style: 'cinematic',
image: "https://chaingpt.s3.dualstack.us-east-2.amazonaws.com/sdk/cgpt-bot.jpg",
isCharacterPreserve: true
});
generatedImages.forEach((buffer, index) => {
const filename = `generated-image-${index + 1}.jpg`;
fs.writeFileSync(filename, buffer);
console.log(`Saved image ${index + 1} to: ${filename}`);
});
}
main();
Note: If isCharacterPreserve is set to true, you must also provide a valid image URL.
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);
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>',
prompt: 'a car being modified',
model: 'velogen',
enhance: 'original',
steps: 3,
height: 1024,
width: 1024,
chainId: 97,
amount: 1,
style: 'cinematic',
traits: [
{
trait_type: 'contrast',
value: [
{ value: 'dark', ratio: 20 },
{ value: 'light', ratio: 80 },
],
},
],
});
console.log(generatedNFT);
}
main();
Generate an NFT from 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.generateNft({
walletAddress: '<your wallet address>',
chainId: 97,
amount: 1,
prompt: 'cars racing to the finish',
model: 'velogen',
enhance: 'original',
steps: 2,
height: 512,
width: 512,
image: 'https://dywmmvb02wrr8.cloudfront.net/document/532d6f9608fa33feeb3455a6ba788483.jpg-1726748667979.jpeg',
});
}
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>',
prompt: 'dragon',
model: 'Dale3',
upscale: true,
height: 1024,
width: 1024,
chainId: 56,
amount: 2,
style: 'cinematic',
traits: [
{
trait_type: 'contrast',
value: [
{ 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>',
});
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();
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>',
isPublic: true,
page: 1,
limit: 10,
});
}
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>',
});
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>',
ids: [1],
name: '<name>',
description: '<description>',
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 your 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();