useBalance
Usage
connect()
must be called and a connection must be initiated before account balance will be returned.
The useBalance
hook returns an accounts’ balance.
If an address is provided, the wallet will return that address’ balance if that address is in the wallet. Otherwise, it will return the currently selected account’s balance.
If the multisig flag is true, the sdk will not fetch until an address is present.
If you create or import a new account after connection, you’ll have to reconnect your dApp to the wallet.
import { useBalance } from '@puzzlehq/sdk';
const { balances, loading, error } = useBalance({ address: 'aleo1t5ympyhrn6rgk7d0h0ktvmvzlymsnwg6w0c0ns5nac7s8d39x5qqtlaynz', multisig: true});
if (error) { return (<p>error loading your balances: {error}</p>)}
if (loading) { return (<p>loading your balances...</p>)}
return ( <div> { balances && balances.map((balance) => ( <> <p>private balance: {balance.values.private}</p> <p>public balance: {balance.values.public}</p> </> ))} </div>)
Types
See the balance page for types.