Once the connection is authorized, you can list all the user accounts using accounts()
.
const accounts = await fuel.accounts();
console.log("Accounts", accounts);
To watch account events, you can use the accounts
event.
function logAccounts(accounts: string) {
console.log("Accounts ", accounts);
}
fuel.on(fuel.events.accounts, logAccounts);
You can also get the current account being used in the wallet using currentAccount()
.
If the return is null
this means that the current account selected by the user is not connected.
const currentAccount = await fuel.currentAccount();
console.log("Current Account", currentAccount);
To monitor events related to the current account, utilize the currentAccount
event. Receiving a null
value from this event indicates that the user's currently selected account is not connected.
If the event receive a null
value this means that the current account selected by the user is not connected.
function logCurrentAccount(account: string) {
console.log("Current Account ", account);
}
fuel.on(fuel.events.currentAccount, logCurrentAccount);
You can keep track of the current account when using React using the useAccount
hook as shown below:
const { accounts } = useAccounts();
const { account } = useAccount();