Skip to main content

Function.useFormattedBalance

function useFormattedBalance(balance: Balance, token?: KeybanToken): string

Formats a balance in a human-readable format using the Keyban client. This is typically used to display the balance of an account, as retrieved by

Parameters

ParameterTypeDescription
balanceBalanceThe raw balance to format.
token?KeybanTokenThe token details, if the balance is not native.

Returns

string

  • The formatted balance as a string.

Example

import { useFormattedBalance } from "@keyban/sdk-react";

const formattedBalance = useFormattedBalance({raw: BigInt(2e17), isNative: true});
console.log(formattedBalance); // "0.2 ETH"