When you swap tokens on a decentralized exchange, the first thing your wallet usually asks for isn't the swap. It is an approval. You are telling a token contract: "this other contract may move my tokens". Without it the exchange couldn't pull your tokens into the trade. With it, that permission can stay in place for months or years after you've stopped using the app.
Most wallet drains I read about don't involve anyone breaking a wallet. They involve an old, forgotten approval. This post explains how approvals work, how to review and cancel them, and includes a small script that shows the same information with code. It is education, not advice.
What an approval is
Tokens like those following the ERC-20 standard keep a ledger inside the token contract: balances, and also a table of allowances, "owner X lets spender Y move up to N of X's tokens". Calling approve(spender, amount) writes into that table. Later, the spender can call transferFrom to move tokens, as long as the amount is within the allowance.
Three details make this riskier than it sounds:
- It doesn't expire. The allowance stays until it is spent or changed. The app can stop existing; your approval doesn't.
- "Unlimited" is common. MetaMask's explainer says most apps request unlimited approvals by default to reduce friction. Technically that is the maximum
uint256value. OpenZeppelin's ERC-20 treats that value as an infinite allowance that isn't reduced when used. - Connecting is not approving. Connecting your wallet to a site only shares your address. An approval requires a separate transaction, or a signed permit message, which your wallet will show you. That is the moment to read carefully.
NFTs work similarly. A single-token approval lets a contract move one specific NFT; setApprovalForAll lets an operator move any NFT you hold in that collection, which is what most marketplaces request.
Why old approvals are dangerous
If the approved contract is later hacked, upgraded to something malicious, or was a phishing contract in the first place, its approval lets an attacker move whatever the allowance covers, with no further action from you. MetaMask's article puts the downside plainly: with an unlimited approval, the entire balance of that token is at risk, and the victim may not know the approval exists until the tokens are gone. Note what approvals can't do: they apply to tokens, not to your chain's native currency such as ETH. But wrapped versions, like WETH, are tokens, so they are covered.
How to review and revoke (with the explorer)
Etherscan provides a Token Approval tool, described in its help centre. Revoke.cash, an independent tool, offers the same function and describes using explorers' pages as an alternative. The steps are broadly the same across them:
- Open the tool from an address you typed or bookmarked yourself, such as the Etherscan Token Approval page found from the explorer's own menu. Don't use a link from a message. Fake "revoke" sites exist, and Gem Wallet's guide warns specifically against switching to similarly named sites or signing something else because a site claims revocation failed.
- Enter your address to see approvals. Viewing doesn't require connecting your wallet. Etherscan notes that only the owner can revoke, which needs a connection.
- Check each tab (ERC-20, ERC-721, ERC-1155) and turn on "Show All Approvals" to include tokens you no longer hold. A token you sold can still have a live approval.
- For each row, look at the spender (the contract that has permission), the allowance and when it was granted. Unknown spender, huge allowance and a date you don't recognise are the combination to act on first.
- Click Revoke and read the wallet prompt. It should set the allowance for that token and spender to zero. It costs a network fee, as MetaMask's explainer notes.
- Check afterwards that the allowance now shows zero or has disappeared.
Two things to remember. Disconnecting a site from your wallet does not revoke anything on-chain; revocation is its own transaction. And revoking only stops future use: it cannot undo transfers that already happened.
The same thing in code
For developers, here is how the review works under the hood, with ethers v6. An Approval event is emitted whenever someone calls approve, so we can find every spender the owner has ever approved. But the event doesn't tell us the current allowance, because an allowance can shrink through transferFrom without a new event (OpenZeppelin's implementation doesn't emit one when spending). So the script uses events to find who to ask, then calls allowance on the contract to get the truth.
approvals.ts
import { Contract, MaxUint256, type ContractRunner } from "ethers";
const ERC20_ABI = [
"event Approval(address indexed owner, address indexed spender, uint256 value)",
"function allowance(address owner, address spender) view returns (uint256)",
"function approve(address spender, uint256 value) returns (bool)",
"function symbol() view returns (string)",
];
export type Allowance = { spender: string; allowance: bigint; unlimited: boolean };
/// Find every spender this owner has ever approved for one token, then read the CURRENT allowance.
/// Approval events tell you who to ask; they do not tell you the current value, because an
/// allowance can shrink through transferFrom without a new Approval event being emitted.
export async function listAllowances(runner: ContractRunner, tokenAddress: string, owner: string): Promise<Allowance[]> {
const token = new Contract(tokenAddress, ERC20_ABI, runner);
const logs = await token.queryFilter(token.filters.Approval(owner));
const spenders = [...new Set(logs.map((l: any) => l.args.spender as string))];
const out: Allowance[] = [];
for (const spender of spenders) {
const allowance: bigint = await token.allowance(owner, spender);
if (allowance > 0n) out.push({ spender, allowance, unlimited: allowance >= MaxUint256 / 2n });
}
return out;
}
/// Revoke = set the allowance back to zero. Costs gas, sent from the owner's wallet.
export async function revoke(signer: ContractRunner, tokenAddress: string, spender: string) {
const token = new Contract(tokenAddress, ERC20_ABI, signer);
const tx = await token.approve(spender, 0n);
return tx.wait();
}
The tests cover both sides:
Approvals.ts
import { expect } from "chai";
import { network } from "hardhat";
import { MaxUint256 } from "ethers";
import { listAllowances, revoke } from "../lib/approvals.js";
const { ethers } = await network.create();
describe("approvals helper", function () {
it("finds live allowances, flags unlimited ones, and revokes them", async function () {
const [me, dex, airdrop] = await ethers.getSigners();
const token = await ethers.deployContract("MockERC20", ["Token", "TKN"]);
const addr = await token.getAddress();
await token.mint(me.address, 1_000n);
await token.connect(me).approve(dex.address, 100n); // limited
await token.connect(me).approve(airdrop.address, MaxUint256); // "unlimited" approval
let found = await listAllowances(ethers.provider, addr, me.address);
expect(found.map((f) => [f.spender, f.unlimited])).to.have.deep.members([
[dex.address, false],
[airdrop.address, true],
]);
await revoke(me, addr, airdrop.address);
found = await listAllowances(ethers.provider, addr, me.address);
expect(found.map((f) => f.spender)).to.deep.equal([dex.address]);
});
it("ignores allowances that were fully used up", async function () {
const [me, spender] = await ethers.getSigners();
const token = await ethers.deployContract("MockERC20", ["Token", "TKN"]);
await token.mint(me.address, 100n);
await token.connect(me).approve(spender.address, 100n);
await token.connect(spender).transferFrom(me.address, spender.address, 100n); // spends it all
expect(await listAllowances(ethers.provider, await token.getAddress(), me.address)).to.deep.equal([]);
});
});
The first test sets a limited approval to one spender and an unlimited one to another, checks that both are found and that only the second is flagged unlimited, revokes it and confirms it's gone. The second test spends an allowance completely and checks that it no longer appears. Both pass on the simulated network.
The "unlimited" check treats anything above half of the maximum value as unlimited, since some apps approve a very large number that isn't exactly the maximum. In real use, add block ranges to the event query, since public providers limit how many logs you can request at once. I haven't done that here.
Habits that keep approvals under control
- Approve what you need, when the app allows. A limited approval caps the loss. The cost is an extra transaction and fee next time.
- Review quarterly. Put it in your calendar. Revoke anything you don't recognise or no longer use.
- Use a separate wallet for experiments. Approvals granted from a wallet with little in it can't take much.
- Watch for signature-based permissions. MetaMask's explainer notes that permit-style systems add deadlines but rely on off-chain signatures that can look harmless. Read every signature request.
- Be suspicious of approval requests that don't match the task. Minting a free NFT shouldn't need a token approval. The pre-interaction checklist goes through what to look at first.
Short checklist
- Approvals persist until you change them; unlimited approvals are common.
- Review in the explorer's approval tool, from an address you trust, with "show all" on.
- Revoke the unknown, the old and the oversized, and confirm afterwards.
- Disconnecting a site does not revoke an approval.
Building a dApp that asks for approvals?
I build front ends that request exact amounts and explain what each prompt does. If you'd like help improving your signing flow, get in touch.
See services Get in touchWhat I ran this against
- Hardhat 3.22.0 (Mocha + ethers template), @openzeppelin/contracts 5.6.1, ethers 6.17.0, solc 0.8.34, Node.js 24.22.1, run on 17 November 2026 on Hardhat's in-process simulated network. The helper script was tested on the simulated network only. Two tests pass: it finds live allowances, flags an "unlimited" one and revokes it; and it ignores an allowance that was fully spent.
- I did not run it against a real wallet or a public RPC. Scanning a long history of
Approvalevents on a public chain needs block ranges and a suitable RPC provider, which this example does not handle. I also did not use the Etherscan or Revoke.cash tools myself; their steps below come from their own help pages. - This is education, not financial or security advice. I'm a developer describing how these tools work; I can't see your situation, and you remain responsible for what you sign.
Sources checked
- Etherscan Information Center, "Token Approvals" (the Token Approval tool: ERC-20, ERC-721 and ERC-1155 tabs, "Show All Approvals", original versus current allowance, and the Revoke button; only the address owner can revoke): info.etherscan.com/tokenapprovals.
- Revoke.cash, "What Are Token Approvals?" and "How to Revoke Token Approvals and Permissions": what are approvals, how to revoke.
- MetaMask, "What are token approvals?" (limited versus unlimited approvals, revoking costs a network fee, connecting a wallet does not itself grant an approval, and Permit2 trade-offs): metamask.com.
- OpenZeppelin Contracts
ERC20.sol(an allowance of the maximumuint256is not decreased ontransferFrom, which makes it semantically an infinite approval, and spending an allowance does not emit anApprovalevent): github.com/OpenZeppelin. - Gem Wallet knowledge base, how to revoke a suspicious approval (disconnecting a dApp does not revoke the on-chain approval; revoking needs a transaction and a fee; it cannot reverse transfers that already happened): docs.gemwallet.com.