Skip to main content
In this tutorial, we’ll explore using the FuseBox Web SDK to build a Next.js application to display Token Address information. This is a prerequisite to building applications where developers can read Token information from the Blockchain and build Dashboards and visualizers. This guide can be relied on for all interactions involving GET requests, which do not cause state changes on the Fuse Blockchain.

Prerequisites

Before we begin, ensure you have the following:
  • Node.js installed on your machine.
  • Code Editor: Use your preferred code editor; VS Code is recommended.
  • An EOA wallet with a private key. You can use an existing one or create a new wallet.
  • A basic understanding of React.js and Next.js.
  • An API key from the Fuse Console. Get one here.

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. We must note that we use TypeScript and Tailwind CSS for this application.

Step 3: Install Dependencies

Install the required dependencies:
The application has two primary functions: GET Token and Token Price details. Both actions will be carried out using the FuseBox Web SDK. We will also use the EthersJS Library for particular Wallet methods. 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 and put up a default `Hello, World!’ text:

Step 5: Dashboard

This is a guide to GET requests using the FuseBox SDK. In this example, we are using the GET Token Details and GET Token Price methods to illustrate how a developer can call the methods and build a simple interactive user interface. To interact with the FuseBox Web SDK, you need to initialize the SDK by parsing an API Key and the Private Key of an EOA. You can get an API Key here. To parse the Data, we will write an asynchronous function called tokenInfo where we await the responses for each token price, as it is a promise. To mount the state and prevent reloads, we will use the useEffect hook. Start with USDT.
Save the file. Go to the tab where the app is running and check the console. You will see the USDC Token Information and Price logged into the console. To display more token information, we can use a Table to display the User Interface. In this example we add more tokens usdc, volt and fuse:

Step 6: The UI

Upate the return statement:

Conclusion

In this tutorial, we’ve demonstrated how to retrieve token information using the FuseBox Web SDK in a Next.js application. With this knowledge, you can build powerful decentralized applications on the Fuse blockchain that interact seamlessly with tokens. Expand on this code and explore further possibilities for adding token information into your projects, and other non-state changing methods available via the SDK.