Welcome to the second part of our RainbowKit guide. In this second part, we will delve deeper into how RainbowKit can be seamlessly integrated into an NFT minting dApp. If you haven't had a chance to explore the previous article, I recommend giving it a read to ensure you're up to date with what we're doing in this second part.

Step-by-Step guide

We will be going through a step-by-step process, starting from scratch, to seamlessly integrate a RainbowKit into a Web3 dApp.

Prerequisites

  • Familiarity with React.

  • Knowledge of Solidity.

  • Development environment: Vs Code or Atom.

Note: As of the time of writing this second article, RainbowKit has undergone some changes in its configuration wrapper since the first part. Please check it out here for the latest updates.

1

Importing the NFT Smart Contract

For this, we’ll be using an NFTs smart contract deployed at this address  (0x9472E4E14342f52c62e74096dcA193a6a5D14be4 ) on the Sepolia Tesnet. I've verified the contract, and you can check out the source code on Etherscan if you're interested.

2

Getting the Contract ABI

In addition to the contract address, we'll require its ABI (What's an ABI). To obtain it, go to the verified contract on etherscan and copy the ABI. Next, create a new folder named constant within the src directory and create a new file inside it named index.js. Copy and paste the copied ABI into index.js.

2.1

3

Interacting With the Contract

Let’s read the totalSupply of the NFT. The smart contract utilized in this tutorial includes a variable named totalSupply, responsible for tracking the overall number of minted NFT. To monitor the totalSupply variable, we need to invoke a function with the same name. We'll utilize the useReadContract hook from our Wagmi node package for this purpose.

3.1

Since we want to display the Nft total supply on the page, let’s render it as shown:

4

Implementing the Minting Functionality

Now, let's incorporate the logic to enable NFT minting! We'll begin by adding a button to the page. Additionally, we'll set up a function called 'minting' to be triggered when someone clicks the button. To execute the NFT minting process, we'll call the createNewNFT function on our smart contract. For this task, we'll leverage the useWriteContract hook from wagmi.

4.1

Let's refine the user interface. Upon a successful NFT mint, users will receive a link to review their NFT transaction on Etherscan. To implement this, we'll employ the useWaitForTransactionReceipt hook from wagmi to obtain the transaction hash.

5

Testing the dApp

To test the dApp, click on the Connect button, and select any of the available wallets provided by Rainbowkit (for this guide, we'll use Metamask). Once selected, you should be able to connect your wallet and establish a connection to the Sepolia testnet, as demonstrated.

5.1

Make sure you have some Sepolia ETH in your account once connected.

5.2

After obtaining some ETH, click the MintNFT button. Confirm the transaction request in your wallet, and you should be able to successfully mint an NFT.

5.3

By now, you should have observed that we have successfully minted an NFT, updating the NFT count accordingly.

5.4

We can then verify this by clicking on View Etherscan, and this should redirect us to our minted NFT transaction on the Sepolia testnet as shown:

There you have it! Our NFT minting page is now ready!

Conclusion

We've reached the conclusion of our RainbowKit Series. This guide has imparted the know-how to create an NFT minting site using Rainbowkit, Wagmi, and React. With the ability to create and interact with an NFT smart contract, feel free to embark on more ambitious projects. Happy coding!