Skip to main content

How do I handle token approvals in a routing flow?

When the user spends an ERC-20 through the router and allowance is too low, submit the approval or preTransactions first, using the spender from the response.

J
Written by Javier Diaz

When the user spends an ERC-20 through the Enso router and allowance is too low, submit the approval — or any required preTransactions — first, using the spender returned in the response. Then submit the route or bundle transaction. Do not hardcode a spender.

Definition

An ERC-20 approval is permission for a spender contract to move a token from the user’s wallet. With the router strategy, that approval is required when allowance is not already high enough. It is not required for every strategy: delegate does not need a prior router approval unless the response says otherwise.

How it works

  1. Request the quote and read whether an approval is required.

  2. Show the token, spender, amount, and chain before the user signs.

  3. Submit the approval transaction and wait for confirmation.

  4. Submit the returned tx as-is.

  5. If allowance is still too low, do not point the approval at an address from a deployments list. Follow the response.

How Enso does this

For a typical EOA flow, use routingStrategy: "router" and, when needed, GET https://api.enso.build/api/v1/wallet/approve. Approve the spender returned for that request. Bundle API docs tell new integrations to inspect preTransactions (in execution order) and treat the legacy approvals list as deprecated there. See Core Concepts and Routing Strategies.

FAQ

Do smart-wallet flows need a router approval?

The delegate strategy is built for smart wallets and does not require a prior approval. Some actions, including borrow, harvest, and repay, must use delegate.

Why is approval required again?

Allowance may be below this input, the spender may differ by strategy or chain, or a previous approval was for a different token.

Related articles

  • What if token allowance is too low?

  • Should I hardcode Enso contract addresses?

  • What is a routing strategy?

  • How do I submit Enso transaction data from my app?

  • How do I add a same-chain swap to my app?

Sources

Did this answer your question?