2021 Fillmore Street #1128


24/7 solutions

Top 10 Cloud Providers

How to Mint NFTs on Flow

This is part of a three step tutorial on minting NFTs on Flow.

A three-step How to on minting NFTs

Navigating back to our allcode-nft directory in terminal that we created in Part 1. Let’s create a new directory within the root of our allcode-nft project called transactions. Within the new transactions directory, create a new file entitled MintAllCodeNFT.cdc.

Inside your MintAllCodeNFT.cdc, insert the following Cadence code:

import AllCodeNFTContract from 0xf8d6e0586b0a20c7

transaction {
let receiverRef: &{AllCodeNFTContract.NFTReceiver}
let minterRef: &AllCodeNFTContract.NFTMinter

prepare(acct: AuthAccount) {
self.receiverRef = acct.getCapability<&{AllCodeNFTContract.NFTReceiver}>(/public/NFTReceiver)
?? panic(“Could not borrow receiver reference”)

self.minterRef = acct.borrow<&AllCodeNFTContract.NFTMinter>(from: /storage/NFTMinter)
?? panic(“could not borrow minter reference”)

execute {
let metadata : {String : String} = {
“name”: “AllCode Logo”,
“street_address”: “Fillmore Street”,
“phone_number”: “415-890-6431”,
“email”: “[email protected]”,
“uri”: “ipfs://QmVH5T7MFVU52hTfQdWvu73iFPEF3jizuGfyVLccTmBCX2”
let newNFT <- self.minterRef.mintNFT()

self.receiverRef.deposit(token: <-newNFT, metadata: metadata)

log(“NFT Minted and deposited to Account 2’s Collection”)

Let’s start at the top of the file. You’ll notice the import statement on the first line. When we deployed the AllCodeNFTContract, We received the following output. We’re merely importing the contract from the public address. After you deploy your contract, then replace your public address accordingly.


AllCode NFT Mint 1

Next, we defined the transaction. We define to reference variables receiverRef and minterRef. In this transaction, we are both the receiver and minter of the NFT. 

After the variable definitions, we have the prepare function. The prepare function validates that the account has the permission to borrow the NFTReceiver and NFTMinter functionality. If the account does not have the permission, then the panic function will be invoked, and the operation will fail. 

Last, we have the execute function. In this function, we build the metadata for the NFT with the uri pointing to IPFS CID for the NFT content that we obtained in our previous post. In this case, the metadata contains extra attributes. We mint the token and deposit the token into the receiverRef of this account.

We’re almost ready to mint our NFT, but first we need to run a few commands in Flow. 

Run the following command:

flow keys generate

This command will generate public and private keys. Remote to store private key safely and don’t share with anyone! 

We will need the private key to sign the transaction, so we can paste that into our flow.json file. We also need to specify the signing algorithm.

Here’s what your accounts object in the flow.json file should look like now:

"accounts": {
"emulator-account": {
"privateKey": "YOUR PRIVATE KEY",
"chain": "flow-emulator",
"sigAlgorithm": "ECDSA_P256",
"hashAlgorithm": "SHA3_256"

If you intend to store any of this project on github or any remote git repository, make sure you do not include the private key. You may want to .gitignore your entire flow.json. Even though we are only using a local emulator, it’s good practice to protect your keys.

Now that we’ve updated this, we can send our transaction. Doing so is as simple as running this command:

flow transactions send ./transactions/MintAllCodeNFT.cdc –signer emulator-account

We are referencing the transaction file we wrote and our signer account from the flow.json. If everything went well, you should see an output like this:

Transaction ID: 7299859f23b3359555f99b520de944ced86bfcbd14da6b13d439b2db96573519

Status ✅ SEALED

ID 7299859f23b3359555f99b520de944ced86bfcbd14da6b13d439b2db96573519

Payer f8d6e0586b0a20c7

Authorizers [f8d6e0586b0a20c7]

Proposal Key:

    Address f8d6e0586b0a20c7

    Index 0

    Sequence 2

No Payload Signatures

Envelope Signature 0: f8d6e0586b0a20c7

Signatures (minimized, use –include signatures)

Events: None

Code (hidden, use –include code)

Payload (hidden, use –include payload)

Now, the last thing we need to do is verify the token is in our account and fetch the metadata. To do this, we’re going to write a very simple script and call it from the command line.

From the root of your project, create a new folder called scripts. Inside of that, create a file called CheckTokenMetadata.cdc. In that file, add the following:

import AllCodeNFTContract from 0xf8d6e0586b0a20c7


pub fun main() : {String : String} {
let nftOwner = getAccount(0xf8d6e0586b0a20c7)
// log(“NFT Owner”)
let capability = nftOwner.getCapability<&{AllCodeNFTContract.NFTReceiver}>(/public/NFTReceiver)

let receiverRef = capability.borrow()
?? panic(“Could not borrow the receiver reference”)

return receiverRef.getMetadata(id: 1)

This script can be thought of in a similar way to read-only methods on Ethereum smart contracts are utilized. They are free and simply return data from the contract.

In our script, we are importing our contract from the deployed address. We are then defining a main function (which is the required function name for a script to run). Inside this function, we’re defining three variables:

  • nftOwner: This is simply the account that owns the NFT. We minted the NFT from the account that also deployed the contract, so in our example those two addresses are the same. This may not always be true depending on the design of your contracts in the future.
  • Capability: We need “borrow” the available capabilities (or functions) from the deployed contract. Remember, these capabilities are access-controlled, so if a capability is not available to the address trying to borrow it, the script will fail. We are borrowing capabilities from the NFTReceiver resource.
  • receiverRef: This variable simply takes our capability and tells the script to borrow from the deployed contract.

Now, we can call functions (that are available to us). In this case, we want to make sure the address in question actually has received the NFT we minted, and then we want to see the metadata associated with the token.

Let’s run our script and see what we get. Run the following on the command line:

flow scripts execute ./scripts/CheckTokenMetadata.cdc

You should see an output something like this for the metadata output:

Result: {“name”: “AllCode Logo”, “street_address”: “Fillmore Street”, “phone_number”: “415-890-6431”, “email”: “[email protected]”, “uri”: “ipfs://QmVH5T7MFVU52hTfQdWvu73iFPEF3jizuGfyVLccTmBCX2”}

Congratulations! You successfully created a Flow smart contract, minted a token, and associated metadata to the token, and stored the token’s underlying digital asset on IPFS. 

import AllCodeNFTContract from 0xf8d6e0586b0a20c7 transaction { let receiverRef: &{AllCodeNFTContract.NFTReceiver} let minterRef: &AllCodeNFTContract.NFTMinter prepare(acct: AuthAccount) { self.receiverRef = acct.getCapability<&{AllCodeNFTContract.NFTReceiver}>(/public/NFTReceiver) .borrow() ?? panic("Could not borrow receiver reference") self.minterRef = acct.borrow<&AllCodeNFTContract.NFTMinter>(from: /storage/NFTMinter) ?? panic("could not borrow minter reference") } execute { let metadata : {String : String} = { "name": "AllCode Logo", "street_address": "Fillmore Street", "phone_number": "415-890-6431", "email": "[email protected]", "uri": "ipfs://QmVH5T7MFVU52hTfQdWvu73iFPEF3jizuGfyVLccTmBCX2" } let newNFT <- self.minterRef.mintNFT() self.receiverRef.deposit(token: <-newNFT, metadata: metadata) log("NFT Minted and deposited to Account 2's Collection") } }

Related Articles

What is Tigera?

What is Tigera?

An AWS Advanced Technology Partner, Tigera delivers Calico and Calico Enterprise for security and networking on EKS, both of which are AWS Containers Competency certified.



Blockchain technology has the potential to be a windfall for musicians, filmmakers, and video game developers. With the advent of new technology, the way we consume entertainment is changing. Vezt assists artists in distributing their tracks on digital channels and in promoting their work.

Top Platforms for NFTs: Polygon and Flow

Top Platforms for NFTs: Polygon and Flow

As blockchain technology continues to develop, we are seeing an increase in the number of platforms, languages, and applications. Your works of art and collectables can now be presented and traded in the form of non-fungible tokens (NFTs), which are a relatively new development.

Free AWS Services List

Download this FREE list of all 200+ AWS services and ensure that you're using the optimal services for your use case to enhance efficiency and save money!

Free AWS Business Continuity Plan Template

Make sure you have the proper business continuity plan explicitly for your AWS infrastructure. Our team of experts built this template using AWS Best Practices so you can ensure it's built to scale! 

Free Cloud Migration Checklist

Without the proper cloud migration strategy, you risk losing time and money. Ensure that your migration process is running smoothly with our FREE cloud migration checklist.

Free AWS Services List

You might be optimizing with the wrong AWS services. Download this FREE list of all 200+ AWS services and ensure that you're using the optimal services for your use case to enhance efficiency and save money!

Download your FREE AWS Business Continuity Plan Template
Download Free 200+ AWS Services Checklist
Download our 10-Step Cloud Migration ChecklistYou'll get direct access to our full-length guide on Google Docs. From here, you will be able to make a copy, download the content, and share it with your team.