Check balances
Decrypt and read confidential token balances using the SDK and React hooks.
Steps
1. Read your own balance
import { createConfig } from "@zama-fhe/sdk/viem";
import { ZamaSDK } from "@zama-fhe/sdk";
import { web } from "@zama-fhe/sdk/web";
import { sepolia } from "@zama-fhe/sdk/chains";
const config = createConfig({
chains: [sepolia],
publicClient,
walletClient,
storage,
relayers: { [sepolia.id]: web() },
});
const sdk = new ZamaSDK(config);
const token = sdk.createToken("0xEncryptedERC20");
const [address] = await walletClient.getAddresses();
const balance = await token.balanceOf(address);
console.log(`Confidential balance: ${balance}`);2. Understand the first-time wallet signature
3. Balance caching
4. Work with raw encrypted values
5. Distinguish "no balance" from "zero balance"
6. Batch decrypt across multiple tokens
7. Read token metadata
8. Use the balance hooks in React
9. Force a manual refresh
Next steps
Last updated