Skip to main content

What is an ERC-20 approval in a routing flow?

An ERC-20 approval lets a router spend the user’s token. Request it only when spending an ERC-20 through the router and the current allowance is too low.

J
Written by Javier Diaz

An ERC-20 approval lets a router spend the user’s token. In a routing flow, you request it only when the route spends an ERC-20 through the router and the current allowance is too low.

Definition

ERC-20 tokens do not move just because a later transaction wants them. The token holder first grants a spender an allowance. The routing transaction can then pull up to that amount. Native gas tokens do not use this approval step.

How it works

  • The app checks whether the spender already has enough allowance for amountIn.

  • If allowance is too low, the user signs an approval transaction first, then signs the routing transaction.

  • If allowance is already sufficient, skip the approval and submit the route.

  • The spender must be the address returned for that quote, not a hardcoded router address.

How Enso does this

For the router strategy, submit any transactions returned in approvals or as preTransactions of type tokenApproval before the shortcut tx. You can also request approval data from GET https://api.enso.build/api/v1/wallet/approve. With delegate, do not send router approvals unless the response requires them. Always use the spender in the current response. See Core Concepts and Routing Strategies.

FAQ

Do native token routes need an approval?

No. Approvals apply to ERC-20 spending through the router. A native input is sent as tx.value.

Do I always need an approval before every route?

No. Request one only when spending an ERC-20 and allowance is too low, or when the quote response includes a required approval.

Related articles

  • How do I handle token approvals in a routing flow?

  • What if token allowance is too low?

  • Should I hardcode Enso contract addresses?

  • What is a routing strategy?

  • How do I use Enso with a smart wallet?

Sources

Did this answer your question?