useAccount
Retrieves the current fuel account and returns the account address <string | null>
.
1const { account } = useAccount();
2console.log(account);
3// fuel1r20zhd...
useAccounts
Retrieves the fuel accounts and returns the addresses of the accounts <string[]>
1const { accounts } = useAccounts();
2console.log(accounts);
3// [fuel1r20zhd..., fuel1qqluc9..., ...]
useBalance
Fetches the balance <BN | null>
of a specified address and asset ID. Additionally, it includes a listener that triggers a balance refresh when the window gains focus.
1const { balance } = useBalance({
2 address: 'fuel1r20zhd...',
3 assetId: '0x000000000...',
4});
5
6console.log(balance);
7// 1000 (example balance)
useChain
Fetches information about the current Fuel network <ChainInfo | null>
.
1const { chain } = useChain();
2console.log(chain.name);
useConnect
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.
1const { connect, connectAsync } = useConnect();
2
3const handleConnect = async () => {
4 connect('Fuel Wallet');
5
6 // Async way
7 await connectAsync('exampleConnectorName');
8};
9
10handleConnect();
useConnectors
Retrieves a list of available connectors Array<FuelConnector>
for connecting to Fuel.
1const { connectors } = useConnectors();
2
3console.log(connectors);
useContractRead
Reads and calls a method from a Fuel contract, returns <InvokeFunctions>
.
1const { contractRead } = useContractRead({
2 contract: _contract,
3 functionName: 'get_count',
4 args: undefined,
5});
1const { contractRead } = useContractRead({
2 contract: { address, abi: countAbi, provider },
3 functionName: 'get_count',
4 args: undefined,
5});
For more information on our Provider, refer to our TS SDK docs
Click here to see an example of an ABI for a Fuel contract
useDisconnect
Facilitates disconnection from the Fuel Wallet. It provides a function UseMutateAsyncFunction<boolean | undefined>
to initiate disconnection.
1const { disconnect } = useDisconnect();
2
3const handleDisconnect = async () => {
4 disconnect();
5
6 // Async way
7 await disconnectAsync();
8};
9
10handleDisconnect();
useIsConnected
Checks whether the user is connected to the Fuel protocol. It provides a boolean
indicating the connection.
1const { isConnected } = useIsConnected();
2console.log(isConnected);
3// true
useNodeInfo
Asynchronously retrieves information about the connected node, checks compatibility with a specified version. The function returns isCompatible
(a <boolean>
), and node information.
1const { isCompatible } = useNodeInfo();
useProvider
Returns the provider from the Fuel object instance.
1const { provider } = useProvider();
useSendTransaction
Hook for signing and sending transactions to the Fuel network.
1const { sendTransaction, sendTransactionAsync } = useSendTransaction();
2
3const handleSendTransaction = async () => {
4 // The amount of coins to transfer.
5 const amount = bn(1);
6
7 // Create a transaction request using wallet helper (check useWallet hook if needed)
8 const transactionRequest = await wallet.createTransfer(
9 destination,
10 amount
11 );
12
13 sendTransaction({
14 address: '0xd7ad97...', // The address to sign the transaction
15 transactionRequest,
16 })
17
18 // Async way
19 await sendTransactionAsync({
20 address: '0xd7ad97...', // The address to sign the transaction
21 transactionRequest,
22 });
23};
24
25handleSendTransaction();
useTransaction
Retrieves transaction information associated with a specific transaction ID.
1const { transaction } = useTransaction({ txId: '0xd7ad97...' });
useTransactionReceipts
Retrieves transaction receipts Array<TransactionResultReceipt>
associated with a specific transaction ID using the useFuel
hook.
1const { transactionReceipts } = useTransactionReceipts({
2 txId: '0xd7ad97...',
3});
useTransactionResult
Retrieves a transaction result associated with a specific transaction ID.
1const { transactionResult } = useTransactionResult({ txId: '0xd7ad97...' });
Customize the data
attribute of the most recently resolved data.
1const { anything } = useTransactionResult({
2 txId: '0xd7ad97...',
3 query: {
4 name: 'anything',
5 },
6});
Transform or select a specific part of the data returned by the query function.
This modification affects the returned data value but does not impact the data stored in the query cache.
1const { receipts } = useTransactionResult({
2 txId: '0xd7ad97...',
3 query: {
4 // you can omit custom "name" if you don't need it
5 name: 'receipts',
6 // ((data: TransactionResult<TransactionType> | null) => T) | undefined
7 select: (data) => data?.receipts,
8 },
9});
useWallet
Retrieves wallet instance <Account | null>
and ensures the presence of a valid address and fuel instance.
1const { wallet } = useWallet({ address: 'fuel1r20zhd...' });