NFTs on Solana
Straight to the code!
Instantiate Cryptum SDK first:
const sdk = new CryptumSdk({
environment: 'testnet',
apiKey: 'YOUR-API-KEY',
})Create NFTs
Create an NFT in Solana.
sdk.nft.create(opts)
opts.protocol(string)(required) - blockchain protocol must beSOLANA.opts.wallet(Wallet)(required) - wallet to sign the transaction with.opts.name(string)(required) - token name.opts.symbol(string)(required) - token symbol.opts.maxSupply(number) - maximum supply for this token (0 for unlimited; 1 for unique; 2 or more for multiple editions). Required to create master edition and copies with limited supply.opts.amount(string) - token amount to be first minted. Required only if maxSupply is 0 or undefined.opts.uri(string)(required) - URI containing NFT metadata.opts.creators(array of SolanaCreators)(optional) - list of creators.opts.royaltiesFee(number)(optional) - royalties fee.opts.collection(string)(optional) - collection address.
This function returns the token address.
Examples:
// Creating NFT with master edition and max supply of 10 copies
const { hash } = await sdk.nft.create({
protocol: 'SOLANA',
wallet,
name: 'NFT',
symbol: 'NFT',
uri: 'https://....',
maxSupply: '10',
})
// Creating NFT without master edition and no max supply
const { hash } = await sdk.nft.create({
protocol: 'SOLANA',
wallet,
name: 'NFT',
symbol: 'NFT',
uri: 'https://....',
amount: '100000',
})Mint NFTs
Mint an additional amount of an existing token.
sdk.nft.mint(opts)
opts.protocol(string)(required) - blockchain protocol must beSOLANA.opts.wallet(Wallet)(required) - wallet to sign the transaction with.opts.token(string)(required) - token address to be minted. If this token is a master edition, this is the address of the master edition token that will be used to create copies (editions).opts.destination(string)(required) - destination address.opts.amount(string) - amount to be minted. Required if this token doesn't have a master edition, leave it undefined otherwise.
This function returns the hash of the transaction.
Example:
const { hash } = await sdk.nft.mint({
wallet: wallets.solana,
protocol: 'SOLANA',
token: 'EzqZ...qnCNd',
destination: 'Er8d....Wud3',
amount: '1',
})Burn NFTs
sdk.nft.burn(opts)
opts.protocol(string)(required) - blockchain protocol must beSOLANA.opts.wallet(Wallet)(required) - wallet to sign the transaction with.opts.token(string)(required) - address of the token that will be burned.opts.amount(string)(required) - token amount to be burned (no decimals).
This function returns the hash of the transaction.
Example:
const { hash } = await sdk.nft.burn({
protocol: 'SOLANA',
wallet,
token: 'EzqZ...qnCNd',
amount: '100',
})Update NFT Metadata
sdk.transaction.updateSolanaNFTMetadata(opts)
opts.wallet(Wallet)(required) - wallet to sign the transaction with.opts.token(string)(required) - address of the token that will be updated.opts.uri(string)(required) - uri containing the updated NFT metadata.
const transaction = await sdk.transaction.updateSolanaNFTMetadata({
wallet,
token: '5N6t...3knE9',
uri: 'https://gateway.pinata.cloud/ipfs/zyx...dcba',
})
const { hash } = await txController.sendTransaction(transaction)
// Log transaction hash
console.log(hash)How do NFTs work on Solana?
Solana NFTs use the Metaplex Standard to add metadata information to regular SPL Tokens.
SPL stands for Solana Program Library, which is a collection of on-chain programs that interact with the Solana blockchain.
You can think of SPL Tokens as equivalent to Ethereum's ERC-20 tokens. The Metaplex protocol is responsible for adjoining extra data onto these ERC-20-like tokens, effectively making them NFTs. If their max supply is set to 1, then it can be seen as an ERC-721 token. For higher or unlimited supplies the NFT can be compared to an ERC-1155 token. But in the end, they're the same thing!
What do I need in order to mint an NFT?
A Cryptum API key is the only requirement to create your brand new NFT for Solana. However, you probably want to add images, titles, symbols, attributes, etc. to your token. This information should be hosted in a service like Pinata or arweave, and not on the token itself.
For this example, we'll suppose you already managed to upload a JSON object to Pinata according to the Metaplex standard:
name
string
Name of the asset.
symbol
string
Symbol of the asset.
uri
string
URI to the external JSON representing the asset
creators
array
public key of each creator
update_authority
string
public key of the metadata owner
primary_sale_happened
boolean
flag describing whether the primary sale of the token happened
seller_fee_basis_points
number
royalties percentage awarded to creators
description
string
Description of the asset.
image
string
URI pointing to asset image.
animation_url
string
URI pointing to asset animation.
external_url
string
URI pointing to an external url defining the asset, the game's main site, etc.
attributes
array
Array of attributes defining the characteristics of the asset.
Make sure to check the latest specifications in the official Metaplex documentation here.
Creating NFTs Programmatically with Cryptum SDK
Step 1
The first prerequisite you will need is the creation of an account and a Project (API Key) on Cryptum Dashboard.
PS: Our dashboard is almost ready! To generate an API Key, contact [email protected]
Step 2
With a valid Cryptum API Key, you can then instantiate the SDK as follows:
Step 3
Towned to create the NFTs:
Make sure the wallet has sufficient funds to pay for the transactions.
Step 4
Call sdk.nft.create function passing your wallet, the desired supply, and the URI to create NFT with limited supply and a master edition.
name is the token name;
symbol is the token symbol;
uri is the metadata URI;
maxSupply is the maximum supply for this NFT (0 for unlimited; 1 for unique; 2 or more for multiple editions). Required if you want to create a master edition and copies with limited supply;
amount is the NFT amount to be first minted. Required only if maxSupply is 0 or undefined;
creators is an optional parameter which consists of an array of creator information;
royaltiesFee is an optional parameter which represents a fee in percentage;
collection is an optional collection address;
To create NFT without limited supply and master edition do this:
There you go! The hash variable now holds the token address, which you can inspect in an explorer such as this one or this other one.
Minting NFTs
To mint more NFTs on Solana you have to pass the wallet with the token's mint authority, the token address, destination address and the amount.
The amount must be 1 or null if this NFT has a master edition.
Transferring NFTs
To transfer NFTs in Solana, just pass the token address, token address, the destination address and the amount:
Burning NFTs
To burn NFTs on Solana you have to pass the wallet that owns the NFT, the token address and the amount:
If you want to check the full Solana NFTs doc, go to:
Last updated
