Flow - Mint and Transfer NFTs

Tatum has a prebuilt Flow NFT contract ready for deployment. The source code is available on GitHub.

Steps

Step_1: Generate a Flow Wallet

Example request:

curl --location --request GET 'https://api.tatum.io/v3/flow/wallet' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "mnemonic": "fabric recipe physical attend foam also inspire swear risk outside monkey palm mutual park civil peasant virtual angle curve tennis follow ### ### ###",
    "xpub": "xpub6EWe9RRoaXxhWR6K1boerSprD2Q84756t8PMoqWS2WCAYmMVxYRXqj5c4PboamiUmxrvKpcoZw2z714kviYL5fQ7VNiktHz3XeBxHqu5Xdh"
}
import {generateFlowWallet} from '@tatumio/tatum';
/**
 * Generate Flow wallet
 * @param mnem mnemonic seed to use
 */
 const mnemonic = "fabric recipe physical attend foam also inspire swear risk outside monkey palm mutual park civil peasant virtual angle curve tennis ### ### ###"
 const wallet = await generateFlowWallet(mnemonic);

Step_2: Generate a Flow Address

Example request:

curl --request GET \
     --url https://api.tatum.io/v3/flow/pubkey/xpub6EWe9RRoaXxhWR6K1boerSprD2Q84756t8PMoqWS2WCAYmMVxYRXqj5c4PboamiUmxrvKpcoZw2z714kviYL5fQ7VNiktHz3XeBxHqu5Xdh/1 \
     --header 'accept: application/json' \
     --header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "address": "0x3dd16e9a72762818"
}
import {Currency, generateAddressFromXPub} from '@tatumio/tatum';
/**
 * Generate address
 * @param currency type of blockchain
 * @param testnet testnet or mainnet version of address
 * @param xpub extended public key to generate address from
 * @param i derivation index of address to generate. Up to 2^31 addresses can be generated.
 * @returns blockchain address
 */
 const xpub = 'bafybeihrumg5hfzqj6x47q63azflcpf6nkgcvhzzm6f6nhic2eg6uvozlq'
 const address = await generateAddressFromXPub(Currency.FLOW, false, xpub, 1);

Step_3: Generate a Flow Private Key

Example request:

curl --request POST \
     --url https://api.tatum.io/v3/flow/wallet/priv \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'x-api-key: {YOUR_API_KEY}' \
     --data '
{
  "index": 1,
  "mnemonic": "fabric recipe physical attend foam also inspire swear risk outside monkey palm mutual park civil peasant virtual angle curve tennis follow ### ### ###"
}'
//Response:
{
    "privateKey": "####",
}

Step_4: Deploy the NFT SmartContract to create a collection

In the case of Flow, it registers a section of a pre-deployed smart contract for you to mint NFTs from. This is because deploying a new smart contract on Flow requires an audit from the Flow team, which can take weeks or months to complete. Tatum Flow smart contract has already been audited and deployed, and you can mint as many NFTs from it as you would like.

🚧

The signing address in the request is the address of the minter. It will only be possible to mint new tokens from this address.

❗️

A Flow address can be used only once to deploy a new NFT contract. If you want to register multiple sections of our smart contract for use, you need to use multiple addresses as deployer/minter addresses.

Example request:

curl --location --request POST 'https://api.tatum.io/v3/nft/deploy/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data-raw '{
    "chain": "FLOW",
    "privateKey": "####",
    "account": "0x3dd16e9a72762818"
}'
//Response:
{
    "txId": "df09b27ca2b4655c4c4d5d4e0a402e6a01c04a0c08f4d9e17d31df0b6358bab7"
}
import {Currency, deployNFT} from '@tatumio/tatum';
const transactionHash = await deployNFT(false, {
    body.chain: Currency.FLOW,
    body.fromPrivateKey: 'e08f2ef94365e1696698f1df3dbfdecf54e255fd51c5db1040ddacf219b79edd',
    body.account: '0x3dd16e9a72762818'
});

Step_5: Retrieve the "SmartContract Address"

Using the transaction ID from the response from the previous call, you can now get the address of the section of the NFT smart contract on the Flow blockchain registered.

Example request:

  • The response will contain the address of the section of the pre-deployed NFT smart contract on the Flow blockchain registered for you to use.
curl --request GET \
  --url https://api.tatum.io/v3/blockchain/sc/address/FLOW/df09b27ca2b4655c4c4d5d4e0a402e6a01c04a0c08f4d9e17d31df0b6358bab7 \
  --header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "contractAddress": "0182e912-329c-4f98-a481-b7515f8a8c51"
}
import {Currency, getNFTContractAddress} from '@tatumio/tatum';
const contractAddress = await getNFTContractAddress(Currency.FLOW, 'df09b27ca2b4655c4c4d5d4e0a402e6a01c04a0c08f4d9e17d31df0b6358bab7');

Step_6: 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_7: Mint a Flow NFT

Example request:

  • The response will contain the ID of the minted token and the ID of the transaction.
curl --location --request POST 'https://api.tatum.io/v3/nft/mint/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_AP_KEY}' \
--data-raw '{
    "to": "0x3dd16e9a72762818",
    "url": "ipfs://bafkreiebg3ugqtumak2ueyf2j2sbggt47hxjvbozkxbgyssebufmbgp3fa",
    "contractAddress": "0182e912-329c-4f98-a481-b7515f8a8c51",
    "chain": "FLOW",
    "privateKey": "####",
    "account": "0x3dd16e9a72762818"
}'
//Response:
{
    "txId": "1e28c9eea5750fccc2db5c34c51d01f040a4ad7e51ffa6e6476d7e69088d7afc",
    "tokenId": 12
}
import {Currency, mintNFTWithUri} from '@tatumio/tatum';
const transactionHash = await mintNFTWithUri(false, {
    to: '0x8cb76aed9c5e336ef961265c6079c14e9cd3d2ea',
    url: 'https://my_token_data.com',
    chain: Currency.FLOW,
    contractAddress: '0182e912-329c-4f98-a481-b7515f8a8c51',
    fromPrivateKey: '####',
    account: '0x3dd16e9a72762818'
});

Step_8: Transfer a Flow NFT

Example request:

  • The response will contain a transaction ID, from which you can obtain the details of the transaction.
curl --location --request POST 'https://api.tatum.io/v3/nft/transaction/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data-raw '{
    "tokenId": "12",
    "chain": "FLOW",
    "to": "0x2d0d7b39db4e3a08",
    "contractAddress": "27320939-3087-490e-a65e-a53c8b06fcd9",
    "privateKey": "####",
    "account": "0x3dd16e9a72762818"
}'
//Response:
{
    "txId": "d7d42e8bb3e5335e8db6ff19c7658004ecc0d7b24c120b9fbe60daaee33e7fdf"
}
import {Currency, transferNFT} from '@tatumio/tatum';
const transactionHash = await transferNFT(false, {
    to: '0x2d0d7b39db4e3a08',
    tokenId: '12',
    chain: Currency.FLOW,
    contractAddress: '27320939-3087-490e-a65e-a53c8b06fcd9',
    fromPrivateKey: '####',
    account: '0x3dd16e9a72762818'
});

Step_9: Get the list of NFTs from a Collection within an address (optional)

Example request:

  • The response will contain the token IDs held by the address entered in the request.
curl --location --request GET 'https://api.tatum.io/v3/nft/balance/FLOW/27320939-3087-490e-a65e-a53c8b06fcd9/0x3dd16e9a72762818' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
[
  10,
  11
]
import {getNFTsByAddress} from '@tatumio/tatum';
const nfts = await getNFTsByAddress(
    Currency.FLOW,
    '27320939-3087-490e-a65e-a53c8b06fcd9/0x3dd16e9a72762818',
);

Step_10: Get the Metadata of a Flow NFT (optional)

Example request:

  • The response will contain the URL of the NFT's metadata.
curl --request GET \
     --url 'https://api.tatum.io/v3/nft/metadata/FLOW/27320939-3087-490e-a65e-a53c8b06fcd9/8?account=0x2d0d7b39db4e3a08' \
     --header 'accept: application/json' \
     --header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
  "data": "https://my_token_data.com"
}
import {Currency, getNFTMetadataURI} from '@tatumio/tatum'
const metadataURI = await getNFTMetadataURI(
    Currency.FLOW,
    contractAddress: '27320939-3087-490e-a65e-a53c8b06fcd9',
    tokenId: '8',
    account: '0x2d0d7b39db4e3a08', 
)

Good to Know

  • Broadcasting transactions on Flow requires a paid plan.
  • Exceptionally, Tatum pays for Flow transaction gas fees, and your account is charged in credits in exchange.