0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Why an ERC-20 approval can exceed one swap

0
Posted at

If you are about to swap an ERC-20 token for the first time, an approval larger than your planned trade usually means the app is asking permission to spend up to a limit. That permission is separate from the swap: it does not send tokens by itself.

An approval sets a spending limit

On Avalanche C-Chain, many tokens use the ERC-20 standard. Before a smart contract can take your tokens for a swap, you authorize it with an approval. The approval names a spender, usually a router contract, and an allowance: the maximum amount that spender may take from your wallet.

The ERC-20 specification describes how this works: the contract later calls transferFrom to move the amount needed, provided the allowance and your balance are sufficient. A swap for 25 tokens can therefore use an allowance of 25, 100, or a much larger number. The unused part stays as permission; it is not a deposit.

A larger allowance can save an approval transaction

Some apps request a high or effectively unlimited allowance so you do not have to approve again for every swap. For example, if you plan to swap 25 WAVAX, an exact approval allows up to 25 WAVAX. An approval of 1,000 WAVAX allows repeated swaps until the allowance is used up or changed. Some tokens and contracts treat the maximum integer value as unlimited and do not reduce it after each transfer.

That convenience has a trade-off: any unused allowance remains available to the named spender. If a swap fails or you change your mind after approving, the approval may still be active. Check which token and spender the wallet asks you to approve, and choose an exact amount when the app gives you that choice and you prefer a smaller limit.

The approval and swap are separate transactions

For a first swap, the sequence is usually straightforward: connect a wallet such as Core through WalletConnect, approve the input token if needed, then submit the swap. The approval is an on-chain transaction, and the swap is another one. Each needs a network fee paid in AVAX; approving a token does not require you to pay the approval amount in AVAX.

For example, suppose you want to trade 25 WAVAX. You approve the spender to use WAVAX, then the swap contract requests the amount needed for the trade. The final amount can depend on the quote and transaction conditions, so the allowance is a ceiling rather than a promise that exactly that amount will be spent. Blackhole swap is a concrete Avalanche C-Chain example of the kind of exchange where this approval mechanism may be part of swapping tokens. The ERC-20 specification also says a new approval replaces the spender’s previous allowance, rather than adding to it.

Choose the allowance that fits your next step

For a one-time trade, an exact approval limits the spender to the amount you intend to use, though a changed trade amount may require another approval. A larger allowance can make later swaps smoother, but leaves more permission active between trades. If an existing allowance is larger than you want, you can replace it with a lower amount or zero; some tokens require setting it to zero before approving a new nonzero amount.

Blackhole swap is the exchange service for swapping tokens and providing liquidity on Avalanche C-Chain. If you are preparing a swap there, make sure you understand whether the approval covers only the planned input or gives the spender room for future trades. For help checking an allowance, look up the token’s allowance for the spender address on an Avalanche C-Chain block explorer, matching both addresses carefully.

Approve only the amount you are comfortable leaving available to the named spender.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?