balance action supports advanced parameters for pulling tokens from external accounts and building routes against estimated token amounts. These parameters extend the basic balance action, which simply returns the on-chain balance of the caller’s wallet.
How It Works
- You submit a
/bundlerequest with abalanceaction that includesaccount(and optionallyestimate) - The API performs an off-chain RPC call to check the account’s token balance
- If no
estimateis provided and the balance is zero, the request returns an error - For router strategy: the token and amount are added to
tokensIn/amountsIn - For delegate / ensowallet strategies: a
transferFromcall is automatically inserted to pull tokens from the external account into the wallet - The API generates approval transactions that the
accountmust sign for the spender contract before the bundle can execute
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
token | AddressArg | Address of the token to check balance | Yes |
estimate | NumberArg | Estimated balance amount in wei. Allows route building without an existing balance on the account. | No |
account | AddressArg | Address of an external account to check balance of. Defaults to the caller’s wallet address when omitted. | No |
When only
token is provided (no account or estimate), the action behaves
exactly as the basic balance check — returning the on-chain balance of the
caller’s wallet. See the basic
usage.Behavior by Routing Strategy
The advanced balance action behaves differently depending on the routing strategy and whetherestimate is provided:
Router
- With
accountonly (noestimate): Theaccountmust approve the router contract. - With
accountandestimate: Theaccountmust approve the EnsoShortcuts contract. The required approval transaction is returned in the bundle response.
Delegate / EnsoWallet
| Strategy | Behavior when account is provided |
|---|---|
delegate | Automatically inserts a transferFrom call to pull tokens from the account into the wallet. The account must approve the delegate contract. |
ensowallet-v2 | Same as delegate — inserts a transferFrom call. The account must approve the EnsoWallet contract. |
Balance Estimates
Whenestimate is provided alongside account, routes are built using the estimated amount rather than requiring the full on-chain balance:
- The API uses the estimate for quoting and route optimization, enabling you to build transactions before the account has the full balance available
Risk Considerations
- EnsoShortcuts contract approval - When using
estimatewith therouterstrategy, theaccountmust approve the EnsoShortcuts contract, which is the main execution contract where tokens will get pulled into. Always revoke this approval in the same transaction. The required approval is returned in the bundle response - pair it with a revoke action to avoid leaving a persistent approval. - Estimate as max amount - The
estimatevalue should be treated as the maximum amount that will be pulled from the account. Swap aggregators used during routing may capture positive slippage, meaning the actual amount consumed can be up to the full estimate even if a smaller amount would have sufficed for the desired output. Set the estimate carefully to limit exposure. - Estimate accuracy - Using
estimatemeans routes are optimized against projected amounts. Significant divergence between the estimate and the actual balance at execution time can cause transaction failure or poor execution prices. - External account security - This feature pulls tokens from an external account via
transferFrom. Always verify theaccountaddress and its approval status before executing.
Examples
Balance with Account and Route
This example checks the USDC balance of an external account with an estimate, then routes the USDC to USDT.- Balance — Check the USDC balance of the external account, using
1000 USDCas the estimate for route building - Route — Route the USDC to USDT using
useOutputOfCallAt: 0to reference the balance from step 1
Balance with Account, TransferFrom, and Route
This example checks the balance, explicitly transfers tokens from the external account, then routes.- Balance — Check the USDC balance of the external account with a
1000 USDCestimate - TransferFrom — Explicitly transfer USDC from the external account to the router, using
useOutputOfCallAt: 0to reference the balance - Route — Route the USDC to USDT
Updated
