EVM NFTs (Ethereum, Polygon and others)

How to create NFTs on Ethereum, Polygon, Celo, BSC, Avalanche C Chain, Stratus, Hyperledger Besu

Straight to the code!

const sdk = new CryptumSdk({
  environment: 'testnet',
  apiKey: 'YOUR-API-KEY',
})

Create NFT

sdk.nft.create(opts)

The smart contract used in this deployment is already precompiled in Cryptum. For more details, you can see the source code here ./contracts/TokenERC721.sol and ./contracts/TokenERC1155.sol.

  • opts.protocol (string) (required) - EVMs only.

  • opts.wallet (Wallet) (required) - wallet creating the token.

  • opts.name (string) (required) - token name.

  • opts.symbol (string) (required) - token symbol.

  • opts.type (string) (required) - token type ERC721 or ERC1155.

  • opts.uri (string) (optional) - token base URI. It is null by default because you can pass specific URI by minting NFTs instead.

This function returns the transaction hash from the blockchain. This hash can be used later to retrieve the token address.

const { hash } = await sdk.nft.create({
  wallet,
  name: 'NFT name',
  symbol: 'NFT',
  type: 'ERC721',
  protocol: 'ETHEREUM',
})

Transfer NFTs

sdk.nft.transfer(opts)

Transfer NFTs.

  • opts.wallet (Wallet) (required) - wallet transferring NFTs.

  • opts.token (string) (required) - token address.

  • opts.amount (string) (required) - token amount to be transferred. (this is in largest unit ether)

  • opts.destination (string) (required) - destination address.

  • opts.protocol (string) (required) - EVMs only.

This function returns the hash of this transferring transaction from the blockchain.

const { hash } = await sdk.nft.transfer({
  wallet,
  protocol: 'AVAXCCHAIN',
  token: '0x1b5e12ca...1b5e12ca',
  destination: '0x31ec6686ee15...07A931b5e12cacb920e',
  amount: '9.129045',
})

Mint NFTs

sdk.nft.mint(opts)

Mint NFTs.

*Obs: This method will only work for the NFTs created with the method sdk.nft.create.

  • opts.protocol (string) (required) - EVMs only.

  • opts.wallet (Wallet) (required) - wallet minting NFTs.

  • opts.token (string) (required) - token address.

  • opts.destination (string) (required) - destination address.

  • opts.amount (string) (required) - token amount to be minted.

  • opts.tokenId (string) (required) - token id to be minted.

  • opts.uri (string) (optional) - metadata URI.

This function returns the hash of this minting transaction from the blockchain.

const { hash } = await sdk.nft.mint({
  protocol: 'CELO',
  wallet,
  token: '0x8888888...333333',
  destination: '0x3333....555555555',
  amount: '10',
  tokenId: 0,
  uri: 'ipfs://...',
})

Burn NFTs

sdk.nft.burn(opts)

Burn NFTs.

*Obs: This method will only work for the NFTs created with the method sdk.nft.create.

  • opts.wallet (Wallet) (required) - wallet burning NFTs.

  • opts.token (string) (required) - token address.

  • opts.amount (string) (required) - token amount to be burnt.

  • opts.tokenId (string) (required) - token id to be burnt.

  • opts.protocol (string) (required) - EVMs only.

This function returns the hash of this burning transaction from the blockchain.

const { hash } = await sdk.nft.burn({
  wallet,
  protocol: 'CELO',
  token: '0x3333333...555555555',
  amount: '3',
  tokenId: 0,
})

Approve ERC-721 NFTs

sdk.nft.approve(opts)

Invoke method "approve" from ERC721-compatible smart contracts.

*Obs: This method will only work for the NFTs compatible with ERC-721 standard.

  • opts.wallet (Wallet) (required) - wallet signing transaction that owns the NFT.

  • opts.token (string) (required) - token address.

  • opts.tokenId (string) (required) - token id to be approved.

  • opts.operator (string) (required) - address to add to the set of authorized operators.

  • opts.protocol (string) (required) - EVMs only.

This function returns the hash of this transaction from the blockchain.

const { hash } = await sdk.nft.approve({
  wallet,
  protocol: 'CELO',
  token: '0x1b5e12ca...1b5e12ca',
  tokenId: '100000',
  operator: '0x9377888...3342232',
})

Set approval for all NFTs

sdk.nft.setApprovalForAll(opts)

Invoke method "setApprovalForAll" from ERC721/ERC1155-compatible smart contracts.

*Obs: This method will only work for the NFTs compatible with ERC-721/ERC-1155 standard.

  • opts.wallet (Wallet) (required) - wallet signing transaction that owns the NFTs.

  • opts.token (string) (required) - token address.

  • opts.isApproved (boolean) (required) - true if the operator is approved, false to revoke approval.

  • opts.operator (string) (required) - address to add to the set of authorized operators.

  • opts.protocol (string) (required) - EVMs only.

This function returns the hash of this transaction from the blockchain.

const { hash } = await sdk.nft.setApprovalForAll({
  wallet,
  protocol: 'CELO',
  token: '0x1b5e12ca...1b5e12ca',
  isApproved: true,
  operator: '0x9377888...3342232',
})ja

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.

Currently, Cryptum supports the following EVM blockchains: Celo, Ethereum, BSC, Avalanche (C-Chain), Polygon, Stratus and Hyperledger Besu. This tutorial works with any of these protocols!

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 }
})

Make sure the wallet has sufficient funds to pay for the transactions.

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:

The amount should be 1 or null if this token type is ERC721.

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:

The amount should be 1 or null if this token type is ERC721.

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:

The amount should be 1 or null if this token type is ERC721.

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