Once the connection is authorized, you can list all the user accounts using accounts()
.
1const accounts = await fuel.accounts();
2console.log("Accounts", accounts);
To watch account events, you can use the accounts
event.
1function logAccounts(accounts: string) {
2 console.log("Accounts ", accounts);
3}
4fuel.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.
1const currentAccount = await fuel.currentAccount();
2console.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.
1function logCurrentAccount(account: string) {
2 console.log("Current Account ", account);
3}
4fuel.on(fuel.events.currentAccount, logCurrentAccount);
You can keep track of the current account when using React using the useAccount
hook as shown below:
1const { accounts } = useAccounts();
1const { account } = useAccount();