Deep Dive on How Cardano NFT Minting is Implemented

Edward Tam
4 min readSep 11, 2021

Introduction

In my previous articles, I introduced our Cardano NFT minting form. I described how easy an NFT can be minted by simply inputting the information and uploading the image. In this one, I am going to mention what’s happening behind the scene. For those interested to know the tech, this one is for you.

Cardano Node & Wallet Services

In order to connect and interact with the Cardano blockchain, we need to setup a Cardano node. IOHK provides us with a set of API & CLI to communicate with the node. And this is through the Cardano wallet.

This is kind of essential step that we have to go through before we can talk to the Cardano blockchain. The actual setup is quite involved (install & configure ghc, cabal, nix and lots of dependent libraries, etc) . But luckily, IOHK offers a “docker” version of both Cardano node & wallet. Having this, we simply need to download the yml file and then bring up the docker images.

wget https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/docker-compose.ymlNETWORK=testnet docker-compose up

There are solutions available in the market that save us from setting up our own node and wallet by simply calling their API. One of those is blockfrost (For those familiar with Ethereum, it’s similar to infura). However, it’s a paid solution for high traffic and it’s less flexible (in the sense that it doesn’t allow us to develop our own API). So, we chose to run our own node and wallet at the end.

Creation of Wallet

Before we can proceed, we need to create our Cardano wallet. This wallet is used for:

  1. receive ADA from our customers
  2. mint new NFT
  3. send NFT to customers’ wallet after its minted

The Cardano wallet from IOHK provides an API to create wallet. Wallet can be created simply with a mnemonic sentence (15 or 24 mnemonic words) and a passphrase (used for sensitive operation like fund sending). If ok, we can get a “wallet ID” that is needed for subsequent actions.

Workflow

The minting workflow is depicted by the following diagram:

Step 1: Upload Information

  • User just need to input the name, long name, description and upload the image for his NFT
  • System will do validation of information at the backend. If validation passes, will proceed to the next step

Step 2: Generate NFT ID

  • System generates a unique ID for the NFT. This ID will be used to identify the NFT during the whole minting process.

Step 3: Calculate Cost

  • The minting cost is calculated. It consists of 4 parts. Details explanation be found in my previous article.

Step 4: Generate Payment Address

  • Based on the wallet ID, a new payment address is created. Please note that a unique payment address is created for each minting action so that the ADA received won’t be mixed up with other transactions.
  • a QR code will be created as well. User using Yoroi on mobile phone can scan this QR code and then send ADA to the payment address right away.

Step 5: Receive ADA

  • User need to send the EXACT amount of ADA to the EXACT payment address. This is for system to identify the sender who will be treated as the owner of the NFT.

Step 6: Mint NFT

  • after enough ADA is received, system will start the actual minting process.
  • The payment address will send the minting transaction to the Cardano blockchain.

Step 7: Send NFT to Owner

  • after the NFT is successfully minted, it will be sent to the user so that he/she will be owner of the NFT.

RESTFUL API

Although there is a set of API provided by Cardano wallet to interact with the blockchain, it’s far from enough to satisfy our needs for NFT minting. We therefore developed a set of API based on the Cardano wallet CLI to tailor our actions. They are:

1: nftid — generate a unique ID

Input: seq_name=CardanoSeq

Output: unique ID

2: fee — calculate the minting fee

Input: nft_name, nft_long_name, description, network

Output: cost of minting NFT

3: address — create new unique payment address

Input: child_index, network

Output: payment address

4: balance — check balance of an address

Input: wallet address, payment_address, lovelace, network

Output: “NFT owner address” if found, “0” if not found

5: mint — send NFT minting transaction

Input: nft_name, nft_long_name, description, image_file, payment_address, signing_key, network

Output: “1” for success, “error-msg” for failure

6: checknft — check if an address owe the NFT

Input: address, nft_name, policy_id, network

Output: “1” if found, “0” if not found

7: send — send an NFT to an address

Input: sender_address, receiver_address, nft_name, policy_id, payment_key, network

Output: “1” if sent, “error-msg” if not sent

In fact, the above are independent API calls that can be re-used to build our NFT marketplace in future. For example, before smart contract comes, we can put our digital artwork for sales. Whenever anybody sends enough ADA to an address (check using API 4), we can send the NFT (using API 7) to the user in return. Later we can confirm if the user really received the NFT (using API 6).

Conclusion

In this article, we went through how our Cardano NFT minting form is implemented at our backend. This implementation is temporary only. With the introduction of Cardano smart contract (expected to come 12 Sep, 2021), we will rely on smart contract and eliminate the trust between system and the user. We will talk about it in details when smart contract is available on Mainnet.

References

--

--

Edward Tam

Owner of IT companies. Blockchain/Crypto enthusiast. Interested in Cardano, Chainlink, Ethereum, Hyperledger,……