modifyTokenBalance
The modifyTokenBalance()
function lets you directly adjust a specific account’s balance for a token, either by adding to or subtracting from it. This is done from or to the token's "unallocated balance", not another user.
Think of it like minting or burning — but instead of affecting total supply, you're just updating who holds what.
When to Use
Mint tokens to an account (from unallocated token balance)
Burn tokens from an account (to unallocated token balance)
Adjust balance after supply changes
Pre-fill or wipe account balances during setup/testing
How It Works (Step-by-Step)
Determine Amount
Use a positive amount to credit (add tokens).
Use a negative amount to debit (remove tokens).
You can also overwrite the balance using
isSet: true
.
// Add 1000 tokens
const amount = 1000n
// OR remove 500 tokens
const amount = -500n
// OR set balance exactly to 0
const amount = 0n
const isSet = true
Method
modifyTokenBalance(
token: TokenOrPending,
amount: bigint,
isSet?: boolean,
options?: { account: Account }
): void
amount
: Can be positive (add) or negative (remove)isSet
: Default is false. If true, sets the exact balance. Otherwise, adds/subtracts from current balance.account
: The target account to modify.
Last updated