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
- Select the network where the NFTs will exist.
- Have ready a Collection (SmartContract) for your NFT to belong.
- Have ready an address with its
privatekey
with native assets. Required to pay for the minting.- If a Minter address was added to the Collection SmartContract, Tatum pays on your behalf. Your account will be charged accordingly.
- Get ready the metadata JSON file.
- Mint the NFT.
Steps
Example request to mint an NFT (CELO Testnet)
Step_1: Generate and upload the Metadata JSON file
- Store: v3 REST API endpoint
- Retrieve: v3 REST API endpoint
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:
Name | Description |
---|---|
chain | The network on which the NFT will be minted. |
contractAddress | The address of your NFT Collection/SmartContract. |
minter | The address of the Tatum NFT minter that you have added as a minter to your smart contract. |
to | The blockchain address of the recipient to whom the NFT will be sent. |
tokenId | The identifier of the NTF that will be minted. |
url | The URL of the metadata (image, audio, video, etc) to be included in the NFT. |
Tatum Minter role addresses:
Environment | Chain | Address |
---|---|---|
Mainnet | BSC, Celo, Ethereum, Harmony, Klaytn, Polygon | 0x49678AAB11E001eb3cB2cBD9aA96b36DC2461A94 |
Testnet | BSC | 0xc16ae5e8c985b906935a0cadf4e24f0400531883 |
Testnet | Celo | 0xBC2eBA680EE50d685cc4Fe65f102AA70AfB27D3F |
Testnet | Ethereum | 0x53e8577C4347C365E4e0DA5B57A589cB6f2AB848 |
Testnet | Harmony | 0x8906f62d40293ddca77fdf6714c3f63265deddf0 |
Testnet | Polygon | 0x542b9ac4945a3836fd12ad98acbc76a0c8b743f5 |
Updated 5 months ago