EVM NFTs (Ethereum, Polygon and others)
How to create NFTs on Ethereum, Polygon, Celo, BSC, Avalanche C Chain, Stratus, Hyperledger Besu
What are NFTs and Collections?
As you may have heard, NFT stands for Non-Fungible Token. This means that, by nature, all tokens that follow this pattern will be inherently different from each other. This ensures, among all the regular blockchain benefits like immutability and decentralization, verifiable uniqueness. In this guide, we will learn how to create (mint) an NFT on the Binance Smart Chain blockchain using our SDK.
But first, let's explain what a Collection is. If you think of NFTs as trading cards, the collection would be the set the card belongs to. Before minting your NFT, you must first create a collection. In more technical terms, Collection is the smart contract that manages all the minting, burning and transfers of all your tokens.
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.
To do so, access our Dashboard and create a DEV-type Project.
Step 2
With a valid Cryptum API Key, you can then instantiate the SDK as follows:
const CryptumSdk = require('cryptum-sdk')
const sdk = new CryptumSdk({
environment: 'testnet', // 'testnet', 'mainnet'
apiKey: "YOUR-API-KEY-HERE",
})
Step 3
Then you must instantiate the wallet that will be used to create the NFTs:
const wallet = await sdk.wallet.generateWallet({
protocol: 'BSC',
mnemonic: 'lorem ipsum dolor sit amet consectetur adipiscing .....',
derivation: { account: 0, address: 0 }
})
Step 4
Call the sdk.nft.create
function passing your wallet, the token type can be either ERC721
or ERC1155
, name of the collection, symbol, and targeted protocol:
const { hash } = await sdk.nft.create({
protocol: 'BSC',
wallet,
symbol: 'NFT',
name: 'NFT',
type: 'ERC721'
})
The function returns the transaction hash of the smart contract deployment to the blockchain. To use this new token you need its address which you can retrive it from like this:
const { contractAddress } = await sdk.transaction.getTransactionReceiptByHash({
protocol: 'BSC',
hash: '0x000.....'
})
Minting NFTs
This function will only work if the NFT was created using the function above sdk.nft.create
Once the transaction has been sent and processed by the blockchain, we can prepare another transaction to mint an NFT into the collection we just created in the previous step. We'll populate the contractAddress
attribute with the contract that was recently deployed in the previous step. Lastly, we'll pass with the destination, tokenId, URI and the amount:
const { hash } = await sdk.nft.mint({
wallet,
protocol: 'BSC',
token: 'TOKEN_ADDRESS',
destination: 'ADDRESS',
tokenId: 0,
uri: 'ipfs://.....',
amount: '1'
})
And that's it! The destination now owns the newly minted NFT from the newly created collection.
Transferring NFTs
This function will only work if the NFT follows the supported standards ERC721 or ERC1155.
To transfer NFTs just pass the token address, tokenId, and the amount:
const { hash } = await sdk.nft.transfer({
wallet,
protocol: 'BSC',
token: 'TOKEN_ADDRESS',
destination: 'ADDRESS',
tokenId: 0,
amount: '1'
})
Burning NFTs
This function will only work if the NFT was created using the functionsdk.nft.create
To burn NFTs just pass the token address, tokenId, and the amount:
const { hash } = await sdk.nft.burn({
wallet,
protocol: 'BSC',
token: 'TOKEN_ADDRESS',
tokenId: 0,
amount: '1'
})
Fetching NFT Information and Metadata
To fetch general token information:
const { hash } = await sdk.nft.getInfo({
protocol: 'BSC',
tokenAddress: 'TOKEN_ADDRESS'
})
To fetch token metadata:
const { hash } = await sdk.nft.getMetadata({
protocol: 'BSC',
tokenAddress: 'TOKEN_ADDRESS',
tokenId: '1'
})
If you want to check the full documentation on NFTs in EVMs, go to:
Last updated