Minting an NFT

Prerequisites

Overview

You can mint your NFT using one of the following:

Minting your NFT

First, upload an image of your newly almost minted NFT. The minting function will receive it as one of its parameters.

📘

Image hosting options

You can upload your selected image using any image-hosting site.

While not covered in this guide, another option would be to use a system like IPFS protocol to store your image on-chain as a decentralized solution.

Then we call upon the function while passing these values with it.

ParameterDescription
senderThe transaction signer address (your address)
tokenIdThe ID value of the newly minted NFT
uriThe NFT's name, description, properties, and image location

Now we will choose to either use Hardhat or the Fireblocks DeFi SDK for the actual deployment. First, we need to make sure they are well set up as described in the Ethereum Smart Contract Development guide and then we follow the steps of the chosen framework.

Using Hardhat

🚧

Hardhat Runtime Environment required

We specifically require the Hardhat Runtime Environment.

This is optional but useful for running the script in a standalone fashion through node <script>.

You can also run a script with npx hardhat run <script>. If you run that script, Hardhat will compile your contracts, add the Hardhat Runtime Environment's members to the global scope, and execute the script.

In the scripts directory, create a new minting script titled: scripts/mint.js

const hre = require("hardhat");
const DatauriParser = require('datauri/parser');
const parser = new DatauriParser();

async function main() {
  const collectionAddress = "<CONTRACT_ADDRESS>";
  const signer = await hre.ethers.getSigner()
  const signerAdderss = await signer.getAddress()
  const nftContract = await hre.ethers.getContractAt("<COLLECTION_NAME>", collectionAddress, signer);
  const tokenData = {
    "name": "<NFT_NAME>",
    "image": "<IMAGE_URL>",
  }

  const tokenURI = parser.format('.json', JSON.stringify(tokenData)).content
  
  const tx = await nftContract.safeMint(signerAdderss, tokenURI);
  await tx.wait()

  console.log("A new NFT has been minted to:", signerAdderss);
  // console.log("tokenURI:", await nftContract.tokenURI(0))
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Using the Fireblocks DeFi SDK

🚧

Deprecation notice

The Fireblocks DeFi SDK has been deprecated. We recommend using the new Fireblocks Web3 Provider.

Fireblocks DeFi SDK instructions

You should already have the contract object and the bridge object from the deployment phase of the contract. Now, create another transaction that represents the minting you want to perform.

const sender = "<your_address>"
const tokenId = 0
const uri = {
    "name": "<NFT_NAME>,
    "image": "<IMAGE_URL>",
}
Const myTx = myContract.populateTransaction.mint(sender, tokenId, uri)

bridge.sendTransaction(myTx).then(res => {
   console.log(res)
})
my_tx = my_contract.functions.mint(sender,
                                  1,
                                  “”"{“name”: “<NFT_NAME>", “image”: “<IMAGE_URL>“,}“”").buildTransaction(
   {“from”: sender,
    “to”: my_bridge.web_provider.toChecksumAddress(my_bridge.external_wallet_address)})

print(my_bridge.send_transaction(my_tx, "Fireblocks Python DeFi SDK Mint"))

Verify your NFT

Now that you have your very own NFT collection, verify it on your Fireblocks workspace and the NFT marketplace Rarible.

In your Fireblocks workspace

Log in to your Fireblocks Console to see whether the last transaction was completed successfully. It will be a Contract Call type.

On Rarible

  1. Visit Rarible using the following URL: https://testnet.rarible.com/user/your_wallet_address/owned
  2. Look for your NFT collection in your Rarible account.

📘

Note

The your_wallet_address value is the address you used to receive the NFT (the vault that deployed the contract).