Skip to main content
In this tutorial, we’ll explore how to use the FuseBox Web SDK to build a Next.js application that interacts with the Fuse blockchain. We’ll cover connecting to MetaMask, initializing a Smart Contract Wallet, and minting NFT Tokens on the Fuse blockchain. To build an NFT DApp with Hardhat and a frontend powered by Account Abstraction on the Fuse blockchain, we’ll create a simple NFT smart contract using Hardhat and integrate it with the Fuse web SDK for account abstraction. This guide is divided into 2 parts: Part 1: The NFT Smart Contract Part 2: The User Interface. Part 2: The User Interface.

Prerequisites

Before we begin, ensure you have the following:
  1. Node.js installed on your machine. You can download it from here.
  2. Code Editor: Use your preferred code editor; VS Code is recommended.
  3. An EOA wallet with a private key. You can use an existing one or create a new wallet.
  4. Basic Understanding of JavaScript: Familiarity with JavaScript will be helpful.

Step 1: Set Up Your Project

Create a new project folder and initialize it using Node.js:

Step 2: Set Up Your Next.js App

Create a new Next.js app:
Answer the required prompts from NextJS in the terminal. It is important to note that we use TypeScript for this application and Tailwind CSS.

Step 3: Install Dependencies

Install the required dependencies:
There are 2 primary functions for the application: Authentication and Minting. Both actions will be carried out using the FuseBox Web SDK. We will also use the EthersJS Library for particular RPC methods. Also, install the EthersJS library; we will use v6.

Step 4: Import Libraries

Open the index.tsx file, delete the default code from NextJS. First import the required libraries:

Step 5: Authentication

To manage Authentication, we have to set up a useState to confirm if a user is logged in or not.
The Connect function is used to set up the Authetication state, the next step is to add the function call in the return as a button, and implement a Loggedin state using a tenary operator. In the return statement inside the main div, add the following code:
Save, and run the code using the command:
The app will be running on localhost:3000 in the web browser. Click on Login, you will be prompted to Login to the App by using your MetaMask to provide a Signature, this will parse your EOA as a Signer to the Fusebox SDK, which will use the information to create a Smart Wallet Account for the EOA. This happens in the section of the Connect method;
Open the console, to see the Smart Contract Wallet logged to the console.

Step 6: Mint an NFT

In part 1 of this guide, we wrote and deployed a Smart Contract for an NFT. We have the Smart Contract address, and we will use the FuseBox SDK to interact with the Smart Contract. Update the index.tsx file by adding the Mint method:
The Mint method can be explained in 2 parts, the first part set up the Transaction structure.
The ethers library has the interface method for interacting with Smart Contracts. We use the encodeFunctionData to parse the function and where available, it’s arguments. The second part initiates the call to the FuseBox method of creating UserOperations using the callContract.
Update the return statement LoggedIn state with a button to call the Mint to mint an NFT.
Click the Mint Button. Open the console and you will see the UserOperation hash and the Transaction hash logged to the Console. You have successfully minted an NFT.

Complete Code

We added the React Toastify Library so you can see the Transaction state from an alert in the UI.