# Approvals

> When an EVM transaction from LayerHop comes with an ERC-20 approval, what it means, and how to send it safely before the swap.

Source: https://docs.layerhop.com/concepts/approvals

An approval is a separate ERC-20 `approve` transaction the user must send before an EVM swap that sells a token (not the native coin), so the provider's contract can pull the tokens. LayerHop tells you when one is needed by returning an `approval` object next to the transaction.

## When does a transaction need an approval?

Selling an ERC-20 token (USDC, USDT…) on an EVM chain requires an allowance for the provider's contract. When it does, `POST /v1/orders` returns the transaction with an `approval`:

```json
{
  "vm": "evm",
  "chainId": 8453,
  "to": "0xa5F5…9934",
  "data": "0x58109c…",
  "value": "0",
  "approval": {
    "token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "spender": "0xa5F5…9934",
    "amount": "100000000"
  }
}
```

| Case | Approval? |
|---|---|
| Selling an ERC-20 token on EVM | Usually, when `approval` is present |
| Selling the native coin (ETH, BNB, POL…) | Never; the amount travels in `value` |
| Any Solana transaction | Never |

## How do I handle an approval?

1. Read the current allowance: `allowance(owner = user, spender)` on `approval.token`.
2. If it is **less than** `approval.amount`, send `approve(spender, amount)` from the user's wallet and **wait for it to be mined**.
3. Then send the main transaction (`to`, `data`, `value`).

```ts
if (tx.vm === "evm" && tx.approval) {
  const { token, spender, amount } = tx.approval;
  const current = await pub.readContract({ address: token, abi: erc20Abi, functionName: "allowance", args: [user, spender] });
  if (current < BigInt(amount)) {
    const hash = await wallet.writeContract({ address: token, abi: erc20Abi, functionName: "approve", args: [spender, BigInt(amount)] });
    await pub.waitForTransactionReceipt({ hash });
  }
}
```

[`POST /v1/simulate`](/concepts/simulation) also checks the allowance and returns `needsApproval: true` when it is too low.

## What are the good practices?

- **Approve the exact amount.** LayerHop returns the exact input amount; avoid unlimited approvals unless the user opts in.
- **The spender is not always `to`.** For 0x the spender is the AllowanceHolder contract while `to` is the settlement contract; for Mayan it is the Mayan Forwarder. Always use `approval.spender`.
- **USDT on Ethereum** rejects changing a non-zero allowance to another non-zero value. If the current allowance is non-zero but too small, approve `0` first, then the new amount.
- **The quote clock keeps running** while the approval confirms. If `expiresAt` has passed, get a new quote before sending the swap.

Gasless approvals (Permit2 or EIP-2612 signatures) are not supported yet; every approval is a regular transaction.
