This guide will walk you through the process of setting up and using the Fuels-ts library in your front-end project.
To begin, you need to add the fuels
dependency to your project. You can do this using the following command:
npm install fuels --save
yarn add fuels
pnpm add fuels
With the Fuels dependency set up, you can now create a React component that will connect to the Fuel provider and retrieve the base asset balance for a given wallet address. Here's an example of how to do this:
import { BN, Provider, Wallet } from "fuels";
import { useEffect, useState } from "react";
function App() {
const [balance, setBalance] = useState(0);
const provider = new Provider("https://beta-3.fuel.network/graphql");
const myWallet = Wallet.fromAddress("0x...", provider);
useEffect(() => {
myWallet.getBalances().then((data) => {
setBalance(new BN(data[0].amount).toNumber());
});
}, []);
return <div>My Balance: {balance}</div>;
}
export default App;
For a more in-depth, step-by-step guide on working with the Fuels ecosystem, check out the Developer Quickstart guide . This guide covers:
Installing all tools needed to develop on the Fuels ecosystem.
Writing your first Sway Project.
Deploying your contract.
Building a simple front-end dApp to interact with your deployed contract.