API ReferenceTokens and balancesInterface
TokenModule
Token operations: metadata, balances, and lookups.
Reached as sdk.tokens on a constructed AnvilSDK instance, which creates
its own modules — consumers never call new TokenModule(...). The class is exported type-only so
its methods appear in the API reference and so integrators can name the type without reaching into
package internals.
Methods
getAccountBalance()
getAccountBalance(params): Promise<bigint>;Returns an account’s wallet balance of one token, in that token’s smallest units.
This is the wallet balance only. Collateral already deposited into the vault is not counted — see VaultModule.getCollateralBalance for that side.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | GetAccountTokenBalanceParams | The token, and the account whose balance to read. |
Returns
Promise<bigint>
The balance in the token’s smallest units.
getMetadata()
getMetadata(params): Promise<TokenMetadata | undefined>;Returns the presentation metadata (currently the logo URL) for a token.
The required profile’s token aliases are applied automatically, which is what lets a testnet token
resolve to its mainnet logo. Passing tokenAliases explicitly overrides the profile’s map.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | GetTokenMetadataParams | The token to look up, and optional alias overrides. |
Returns
Promise<TokenMetadata | undefined>
The metadata, or undefined when no logo resolves.
getToken()
getToken(params): Promise<Token | undefined>;Returns the Token at an address: name, symbol, and decimals read from the ERC-20
contract, with logo metadata attached when the asset repo has one.
Each call reads the token contract and metadata source. A contract that answers symbol() with an
empty string yields undefined rather than throwing.
It is not a general “is this an ERC-20?” probe: an address with no ERC-20 interface at all — an EOA, or an unrelated contract — makes the underlying reads revert, and this throws. Catch if you are checking an address the user supplied.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | GetTokenParams | The token address to look up. |
Returns
Promise<Token | undefined>
The token, or undefined if the contract reports an empty symbol.
Throws
InvalidArgumentError If params.address is missing. Thrown
before any read.
validateApprove()
validateApprove(params): Promise<ValidationIssue[]>;Validates the parameters of an ERC-20 approve call: address format, and an amount of zero or more.
Zero is valid — it is how an approval is revoked.
Unlike the other validate* methods this one does not gate a matching build*Workflow call.
erc20Approve is a generic step that other operations compose internally (the deposit-to-vault
workflow prepends one when the vault is short), exposed here so a headless caller can check it
standalone.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | Partial<ERC20ApproveParams> | The partial approve parameters to check. |
Returns
Promise<ValidationIssue[]>
The issues found: empty means checked and valid — a rule whose own required field is absent reports
FieldRequired rather than being silently skipped, so empty never means “nothing could run.”
Non-empty means domain-invalid. Never partial — an infrastructure failure rejects instead of
resolving.