⌘K

Icon SunFilledIcon MoonStars
Hooks Reference

Icon LinkReact Hooks Reference

Icon LinkuseAccount

Retrieves the current fuel account and returns the account address <string | undefined>.

const { account } = useAccount();
console.log(account);
// fuel1r20zhd...

See the source file Icon Link

Icon LinkuseBalance

Fetches the balance <number | undefined> of a specified address and asset ID. Additionally, it includes a listener that triggers a balance refresh when the window gains focus.

const { balance } = useBalance({
  address: 'fuel1r20zhd...',
  assetId: '0x000000000...',
});
 
console.log(balance);
// 1000 (example balance)

See the source file Icon Link

Icon LinkuseChain

Fetches information about the current Fuel network <ChainInfo | undefined>.

const { chain } = useChain();
console.log(chain.name);
// beta-4

See the source file Icon Link

Icon LinkuseConnect

Facilitates the connection to the Fuel wallet. Allows selecting a connector by name. It also provides a function <UseMutateAsyncFunction<boolean | undefined>> to initiate the connection and relevant mutation properties for managing the connection state.

const { connect } = useConnect();
 
const handleConnect = async () => {
  await connect('exampleConnectorName');
};
 
handleConnect();

See the source file Icon Link

Icon LinkuseConnectors

Retrieves a list of available connectors <Array<FuelWalletConnector>> for connecting to Fuel.

const { connector } = useConnectors();
 
console.log(connectors);

See the source file Icon Link

Icon LinkuseDisconnect

Facilitates disconnection from the Fuel Wallet. It provides a function <UseMutateAsyncFunction<boolean | undefined>> to initiate disconnection.

const { disconnect } = useDisconnect();
 
const handleDisconnect = async () => {
  await disconnect();
};
 
handleDisconnect();

See the source file Icon Link

Icon LinkuseIsConnected

Checks whether the user is connected to the Fuel protocol. It provides a boolean indicating the connection.

const { isConnected } = useIsConnected();
console.log(isConnected);
// true

See the source file Icon Link

Icon LinkuseNodeInfo

Asynchronously retrieves information about the connected node, checks compatibility with a specified version. The function returns isCompatible <boolean> and node information.

const { isCompatible } = useNodeInfo();

See the source file Icon Link

Icon LinkuseProvider

Returns the provider from the Fuel object instance.

const { provider } = useProvider();

See the source file Icon Link

Icon LinkuseTransaction

Retrieves transaction information associated with a specific transaction ID by using the provider.getTransaction method.

const { transaction } = useTransaction({ txId: 'fuel1r20zhd...' });

See the source file Icon Link

Icon LinkuseTransactionReceipts

Retrieves transaction receipts <TransactionResponse.Receipts> associated with a specific transaction ID using the useFuel hook.

const { transactionReceipts } = useTransactionReceipts({
  txId: 'fuel1r20zhd...',
});

See the source file Icon Link

Icon LinkuseWallet

Retrieves wallet instance <FuelWalletLocked | undefined> and ensures the presence of a valid address and fuel instance.

const { wallet } = useWallet({ address: 'fuel1r20zhd...' });

See the source file Icon Link