Sub topic 11
Token approvals and signature requests
This chapter covers the two permissions that let a third party move your tokens: onchain approvals and offchain signatures. It assumes you can read a block explorer page, know what a wallet transaction is, and have used a DEX. You do not need to write Solidity, but the code examples use ethers v6.
Why approvals exist
An ERC-20 token lives in a contract, not in your wallet. A balance is a number in the token contract's balanceOf mapping. When you swap on a DEX, the DEX contract must move tokens out of your balance. The contract cannot do that on its own, so the standard has a two-step pattern:
- You call
approve(spender, amount)on the token. The token records an allowance for that spender. - The spender later calls
transferFrom(you, recipient, amount). The token checks the allowance, lowers it, and moves the tokens.
The allowance is stored in the token contract as allowance[owner][spender]. Your wallet does not need to be online, and you do not need to sign again. Once the allowance exists, the spender can use it at any time until it runs out or you change it.
This is the risk. An approval is a standing permission, and it is separate from the trade that prompted it.
Unlimited approvals
Many apps ask for an amount of 2^256 - 1, shown in wallets as "unlimited" or a very long number. Apps do this to save you gas on later trades, because the allowance never needs a refresh.
| Approval type | Convenience | Exposure if the spender is compromised or malicious |
|---|---|---|
| Exact amount | You approve again for each trade | Limited to the approved amount |
| Unlimited | One approval covers every future trade | Your whole balance of that token, now and in future |
Unlimited exposure also covers tokens you buy later. If you approve a spender for token X today and deposit more X next month, the spender can take that too.
A legitimate, audited router with an unlimited approval is a common and usually acceptable risk. An unknown contract from a new token's claim page is not. The same approval that is routine for a major DEX router is a red flag for an address you cannot identify.
Approval flow and where it goes wrong
A malicious site does not need your private key. It only needs you to approve once.
Approval red flags in a launch or airdrop
Watch for these in a wallet confirmation window:
- An approval during a "claim." A real claim transfers tokens to you. It does not need permission to spend your tokens. If a claim asks you to approve a token you already hold, stop.
- An unfamiliar spender. Check the spender address on a block explorer. Is it a verified contract? How old is it? Is it a known router or a freshly deployed contract?
- Unlimited amount for a first-time interaction with an unknown app.
- Approval for a token unrelated to the stated action. An airdrop for token A that asks to approve your USDC or WETH is a drain attempt.
setApprovalForAllon an NFT collection. This grants control of every NFT in that collection to the operator, which is a broader grant than a single token approval.- A fake token that prompts the approval. Scam tokens sent to your wallet can have names like "Visit site to claim." The site then asks for an approval.
Signature requests
Not every permission is a transaction. Wallets also ask you to sign messages. Signing is free (no gas), so it feels harmless. It is not, because some signatures authorize movement of funds when someone else submits them onchain.
There are three common kinds.
| Kind | What it is | Typical safe use | Risk |
|---|---|---|---|
| `personal_sign` | A plain text message, shown as readable text | Sign-in with Ethereum (SIWE) login | Low if the text is readable and only proves you own the address. Risky if you sign opaque hex. |
| EIP-712 typed data | A structured message with named fields and a domain | Orders on marketplaces and DEXs | Medium to high. The fields can encode a transfer or a permit. |
| Raw transaction or `eth_sign` of a hash | A hash you cannot read | Almost none for ordinary users | High. You cannot see what you authorize. |
Permit signatures
EIP-2612 permit lets a token owner sign an approval offchain. The spender submits that signature to the token's permit function, and the token sets the allowance. No approval transaction from you is needed, and you pay no gas.
This is useful, since it saves a transaction. It is also a favorite tool for drainers. The wallet pop-up shows a typed-data request with a field list. You will see items like owner, spender, value, nonce, and deadline. The attacker keeps the signature and uses it whenever they like before the deadline.
Related signature systems have the same property:
- Permit2 (Uniswap's shared approval contract) lets you approve Permit2 once, then grant time-limited, amount-limited permissions by signature. A signature to a malicious spender through Permit2 can move any token that you have approved to Permit2.
- Marketplace order signatures (for example Seaport listings) can list your NFT for almost no price. The attacker then buys it.
A signature does not appear in a block explorer's approval list until the attacker submits it. You can sign today and be drained next week.
What to read in a typed-data request
- Domain. The
name,chainId, andverifyingContract. Does the contract match the token or app you meant to use? - Primary type. Names such as
Permit,PermitSingle,PermitBatch, orOrdertell you what is authorized. - Spender or operator. Is it an address you recognize?
- Value. A huge number means unlimited.
- Deadline or expiry. A far-future deadline (or max value) means the signature stays usable for a very long time.
If the wallet shows only a hex blob and a "sign" button, refuse. Use a wallet or a simulation feature that decodes the request and previews the balance changes.
Reading approvals with a script
Before you interact with a token, you can read who holds permissions over your balance. This script reads an allowance directly from the token.
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const abi = [
"function allowance(address owner, address spender) view returns (uint256)",
"function symbol() view returns (string)",
"function decimals() view returns (uint8)",
];
const token = new ethers.Contract(process.env.TOKEN_ADDRESS, abi, provider);
const [symbol, decimals, allowance] = await Promise.all([
token.symbol(),
token.decimals(),
token.allowance(process.env.OWNER_ADDRESS, process.env.SPENDER_ADDRESS),
]);
const unlimited = allowance >= 2n ** 255n;
console.log(`${symbol} allowance:`, ethers.formatUnits(allowance, decimals));
console.log("effectively unlimited:", unlimited);The allowance view only covers the one spender you query. To find all spenders, use an approval checker that scans Approval events for your address, since the token contract has no function to list them.
Revoking an approval
Revoking an ERC-20 approval means setting the allowance to zero. This is an onchain transaction, so it costs gas.
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const abi = ["function approve(address spender, uint256 amount) returns (bool)"];
const token = new ethers.Contract(process.env.TOKEN_ADDRESS, abi, wallet);
// Setting the allowance to zero revokes the spender's permission to move this token.
const tx = await token.approve(process.env.SPENDER_ADDRESS, 0n);
await tx.wait();
console.log("revoked in tx", tx.hash);For most people, a revoke tool in the wallet or a reputable approval-management site is easier and avoids pasting a private key into a script. Never put a private key in a script on a shared machine.
Limits of revoking
- Revoke cannot reverse a drain. It stops future pulls only.
- A signed permit may still be live. If you signed a permit but the attacker has not yet submitted it, revoking the approval does nothing, because no approval exists yet. A permit has a nonce. Calling
permitwith your nonce, or any action that increments it, invalidates older signatures on some tokens. Not every token supports a nonce-invalidating call, so the reliable defense is to move the funds to a new wallet. - Permit2 needs its own revoke. Revoking the token's allowance to Permit2 removes the root permission. Revoking only the inner Permit2 allowance leaves the token-to-Permit2 approval intact.
- Gas matters under attack. A drainer may be sweeping tokens at the same time. Move the most valuable assets first.
Spotting a malicious spender
A contract is more likely safe when:
- It is verified on the explorer and the source matches a known project.
- It is a documented address listed on the project's official docs, reached from a source you typed or bookmarked yourself.
- It has a long history and many unrelated users.
It is suspicious when:
- It was deployed hours or days ago.
- The code is unverified.
- It appears in your wallet's warning list or an explorer label such as "Phishing" or "Fake_Phishing."
- It is an externally owned account (a normal wallet address) instead of a contract. Giving an approval to a plain wallet is almost always wrong.
Habits that reduce exposure
- Use a separate wallet for claims and new launches, holding only small amounts. Keep long-term holdings in a different wallet that never connects to unknown sites.
- Prefer exact approvals. Many wallets let you edit the approval amount in the confirmation window.
- Read every signature request. If you cannot explain in one sentence what it authorizes, do not sign.
- Use transaction simulation if your wallet offers it.
- Review and revoke old approvals on a schedule, after each batch of experiments.
- Reach sites through bookmarks, not links in replies, direct messages, or ads.
Summary of checks
| Prompt | Question to ask | Stop if |
|---|---|---|
| Approval transaction | Who is the spender, and how much? | Unknown spender, unlimited amount, or unrelated token |
| Typed-data signature | What type, spender, value, and deadline? | `Permit` or `Order` with an unknown spender |
| Plain message | Is it readable text that only proves ownership? | Hex blob or text that mentions transferring |
| `setApprovalForAll` | Which collection and operator? | The operator is not a known marketplace |
Exercise
You visit a site that promises an airdrop for a new token. After you connect, your wallet shows an EIP-712 request with primary type Permit, a spender you do not recognize, a value of 115792089237316195423570985008687907853269984665640564039457584007913129639935, and a deadline far in the future. The site says this "confirms eligibility." What is happening, and what do you do?
Show answer
The request is an EIP-2612 permit that would let the unknown spender move any amount of the named token from your wallet (the value is 2^256 - 1, which is unlimited) until the far-off deadline, with no gas cost to you and no approval transaction. Eligibility checks do not need this. Reject the request, disconnect the site, and check the spender address on a block explorer. If you already signed a similar request in the past, move the tokens to a fresh wallet, because revoking an approval does not cancel a signed permit that has not been submitted yet.
Exercise
Why does revoking an approval by setting the allowance to zero not protect you from a permit signature you gave earlier, and what is a reliable defense?
Show answer
A permit signature is not an onchain allowance until the spender submits it to the token's permit function. Until then there is no allowance to set to zero. The attacker can submit the signature any time before its deadline, which creates a new allowance and lets them pull tokens. Some tokens let you invalidate older signatures by consuming the nonce, but support varies. The reliable defense is to move the affected assets to a new wallet whose address never signed the permit.
Exercise
A claim site asks you to approve USDC before you can receive a new token. The token you are claiming is unrelated to USDC. Give two reasons this is a red flag.
Show answer
First, a claim sends tokens to you and does not need permission to spend your tokens. Second, the approval is for an unrelated asset, which suggests the spender intends to pull USDC from your wallet. Checking the spender address, which is likely a new or unverified contract or a plain wallet, would add further evidence.