EVM - Mint NFTs (ERC-721)

To mint an NFT you need a Collection to which said NFT must belong. Once you have the Collection SmartContract, minting NFTs just takes a few steps.

πŸ“˜

The following steps and examples are based on Celo Alfajores (testnet).

Minting an NFT

  1. Select the network where the NFTs will exist.
  2. Have ready a Collection (SmartContract) for your NFT to belong.
  3. Have ready an address with its privatekey with native assets. Required to pay for the minting.
    1. If a Minter address was added to the Collection SmartContract, Tatum pays on your behalf. Your account will be charged accordingly.
  4. Get ready the metadata JSON file.
  5. Mint the NFT.

Steps

Example request to mint an NFT (CELO Testnet)

Step_1: Generate and upload the Metadata JSON file

Example request:

//First upload the NFT image
curl --location --request POST 'https://api.tatum.io/v3/ipfs' \
--header 'x-api-key: {YOUR_API_KEY}' \
--form 'file=@"/Users/{username}/Documents/tatum_nft_example.jpeg"'
//Response
{
    "ipfsHash": "bafkreif6ifegpj74w6biowzzbswqwvg6c5t6hhtwsrmpxhweg6yn7zxm7e"
}

//After that, create a JSON file and upload this new file
//File format:
//  {
//    "name": "Tatum NFT for Diagram example",
//    "description": "This is an NFT minted as an example.",
//    "image": "ipfs://bafkreif6ifegpj74w6biowzzbswqwvg6c5t6hhtwsrmpxhweg6yn7zxm7e"
//  }

curl --location --request POST 'https://api.tatum.io/v3/ipfs' \
--header 'x-api-key: {YOUR_API_KEY}' \
--form 'file=@"/Users/{username}/Documents/Tatum_NFT_example.json"'
//Response
{
    "ipfsHash": "bafkreiebg3ugqtumak2ueyf2j2sbggt47hxjvbozkxbgyssebufmbgp3fa"
}

πŸ“˜

Find the step-by-step guide in the following article.

Step_2: Estimate the Gas Fees to Mint an NFT

Example request:

curl --location 'https://api.tatum.io/v3/blockchain/estimate' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
  "chain": "CELO",
  "type": "MINT_NFT",
  "sender": "0xBC2eBA680EE50d685cc4Fe65f102AA70AfB27D3F"
}'
//Response:
{
    "gasLimit": 260000,
    "gasPrice": 15
}

Step_3: Check the current "nonce" value from the sender's address

Find more about the nonce in the following article.

Example request:

curl --location 'https://api.tatum.io/v3/celo/transaction/count/0xbc2eba680ee50d685cc4fe65f102aa70afb27d3f' \
--header 'x-api-key: {Mainnet_API_KEY}'
//response:
978 // Current nonce value in decimals

Step_4: Mint the NFT

Example request:

curl --location 'https://api.tatum.io/v3/nft/mint/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
    "chain": "CELO",
    "to": "0x40245fa66666508e4121f4400819eef4b08ac4bf",
    "contractAddress": "0x0935a78C8a268c8ED0590E5A8d4409f7604Bed1A",
    "tokenId": "001",
    "url": "ipfs://bafkreiebg3ugqtumak2ueyf2j2sbggt47hxjvbozkxbgyssebufmbgp3fa",
    "feeCurrency": "CELO",
    "nonce": 978,
    "fee": {
        "gasPrice": "15",
        "gasLimit": "26000"
    },
    "fromPrivateKey": "####"
}'
//Response:
{
    "txId": "0xd16536eea02ddffd2deee2db5e2c053ee429526758420477781082c7a5465aa7"
}
curl --location --request POST 'https://api.tatum.io/v3/nft/mint/' \
--header 'x-api-key: {YOUR_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"chain": "CELO",
"tokenId": "001",
"to": "0x40245fa66666508e4121f4400819eef4b08ac4bf",
"url": "ipfs://bafkreiebg3ugqtumak2ueyf2j2sbggt47hxjvbozkxbgyssebufmbgp3fa",
"contractAddress": "0x0935a78C8a268c8ED0590E5A8d4409f7604Bed1A", // Your NFT Collection
"minter": "0xBC2eBA680EE50d685cc4Fe65f102AA70AfB27D3F", // If there's no "minter", PrivateKey must be used instead.
"feeCurrency": "CELO"
}'
//Response:
{
    "txId": "0xd16536eea02ddffd2deee2db5e2c053ee429526758420477781082c7a5465aa7"
}

Parameters:

NameDescription
chainThe network on which the NFT will be minted.
contractAddressThe address of your NFT Collection/SmartContract.
minterThe address of the Tatum NFT minter that you have added as a minter to your smart contract.
toThe blockchain address of the recipient to whom the NFT will be sent.
tokenIdThe identifier of the NTF that will be minted.
urlThe URL of the metadata (image, audio, video, etc) to be included in the NFT.

Tatum Minter role addresses:

EnvironmentChainAddress
MainnetBSC, Celo, Ethereum, Harmony, Klaytn, Polygon0x49678AAB11E001eb3cB2cBD9aA96b36DC2461A94
TestnetBSC0xc16ae5e8c985b906935a0cadf4e24f0400531883
TestnetCelo0xBC2eBA680EE50d685cc4Fe65f102AA70AfB27D3F
TestnetEthereum0x53e8577C4347C365E4e0DA5B57A589cB6f2AB848
TestnetHarmony0x8906f62d40293ddca77fdf6714c3f63265deddf0
TestnetPolygon0x542b9ac4945a3836fd12ad98acbc76a0c8b743f5