Balances
Use this module when your UI needs to show how much of a token a wallet holds, whether a spender is already allowed to spend that token, or when the user must approve before another write (swap, stake, farm deposit, etc.).
Amounts are display decimals (what you show the user), not raw/smallest-unit. approve uses a Wallet adapter.
Rules
- Pass
owneronly when you need a specific address; omit it when awalletis configured — Whose wallet (owner). approveis its own write. It does not run inside swap, stake, or farm — call it when allowance is too low, then call the other write.- After a successful approve, re-read
getAllowance(or rely on your next write failing withINSUFFICIENT_ALLOWANCEif you skip the check). approvecan incur gas and the service fee when it runs. The SDK does not return acostslist beforeapprove— Fees and costs.
Where does spender come from?
spender is the contract address that will move the token after approval (router, staking contract, farm, …). Take it from a known source below — not from placeholder examples.
| Source | When |
|---|---|
catalog.getDeployment | Look up the ledger’s DeploymentManifest and use the address for the contract your flow needs (e.g. the Router entry for swaps). |
| Product / integration notes from Nutrimatic | When your integration is given a specific spender for a program |
Pass that address into getAllowance and approve. Do not hard-code random addresses from examples (0xspender… is a placeholder).
balances.getBalance
How much of one instrument an address holds. Omit owner to use the connected wallet.
const balance = await sdk.balances.getBalance({
instrumentId: 'evm:421018:instrument:42',
})Parameters
| Field | Type | Description |
|---|---|---|
instrumentId | InstrumentId | Token to look up (catalog instrument id). |
owner | string | Optional. Address to query. Omit to use the connected wallet — Whose wallet (owner). |
Returns — Balance
| Field | Type | Description |
|---|---|---|
instrumentId | InstrumentId | Same asset you asked for. |
amount | string | Held amount as a display decimal (e.g. "12.5"). Show as-is. |
owner | string | Address that was queried. |
ledger | LedgerId | Canonical ledger id (never an alias). |
Example response:
{
"instrumentId": "evm:421018:instrument:42",
"amount": "12.5",
"owner": "0xabc…",
"ledger": "evm:421018"
}balances.getAllowance
How much of a token a spender (usually a contract) may still move on behalf of the owner. Use this before a write that needs approval, or to decide whether to call approve.
const allowance = await sdk.balances.getAllowance({
instrumentId: 'evm:421018:instrument:42',
spender: '0xspender…',
})Parameters
| Field | Type | Description |
|---|---|---|
instrumentId | InstrumentId | Token whose allowance you are reading. |
spender | string | Contract that may spend — from the deployment manifest (not a made-up address). |
owner | string | Optional. Token owner. Omit to use the connected wallet — Whose wallet (owner). |
Returns — Allowance
| Field | Type | Description |
|---|---|---|
instrumentId | InstrumentId | Token this allowance is for. |
owner | string | Address that owns the tokens. |
spender | string | Address that may spend. |
amount | string | Remaining approved amount (display decimal). "0" means approve (or raise the allowance) before the next write. |
ledger | LedgerId | Canonical ledger id. |
Example response:
{
"instrumentId": "evm:421018:instrument:42",
"owner": "0xabc…",
"spender": "0xspender…",
"amount": "0",
"ledger": "evm:421018"
}balances.approve
Ask the user to allow a spender to use up to amount of a token. Signing uses purpose: 'approve'.
const handle = await sdk.balances.approve({
instrumentId: 'evm:421018:instrument:42',
spender: '0xspender…',
amount: '100',
})Parameters — ApproveRequest
| Field | Type | Description |
|---|---|---|
instrumentId | InstrumentId | Token to approve. |
spender | string | Who may spend after this succeeds — same address you used in getAllowance (where it comes from). |
amount | string | Max amount to approve (display decimal). |
deadline | number | Optional. Unix time in milliseconds — do not proceed after this. |
Returns — ExecutionHandle
Same ExecutionHandle as other writes. Poll settlement.track until confirmed or failed if still running.
Example response:
{
"id": "exec_01HZZ…",
"status": "confirmed",
"ledger": "evm:421018",
"txRef": "0xdef…"
}Errors
READ_ONLY_MODE, CAPABILITY_NOT_AVAILABLE, WALLET_REQUIRED, USER_REJECTED, INSTRUMENT_NOT_FOUND, LEDGER_NOT_SUPPORTED.
→ Whose wallet (owner) · Positions · Staking · Write operations