Sub topic 11
Token Approvals and Signature Requests
Prerequisites and the permission model
This chapter assumes you understand wallet addresses, transactions, tokens, decentralized exchanges, and basic block explorer pages.
An ERC-20 approval gives a spender permission to move a specified amount of your token. The spender is often a decentralized exchange router, lending protocol, bridge, or claim contract. After you approve it, the spender can call transferFrom without asking you to approve every transfer.
An approval is separate from sending tokens. You still own the tokens, but another contract has a standing allowance. If that contract is malicious or compromised, it may use the allowance later.
| Action | What it authorizes | Main risk |
|---|---|---|
| Token approval | A spender moves a chosen token up to an allowance | The allowance remains active |
| Unlimited approval | A spender moves future balances of that token | One mistake can expose later deposits |
| Permit signature | A signed message creates or changes an allowance | You may authorize it without seeing a transaction |
| NFT operator approval | An operator manages all NFTs in a collection | Every matching NFT may be exposed |
Transaction approvals and their risks
A normal approval transaction shows the token, spender, and allowance. Check the spender address independently. A familiar website can still point to the wrong contract, and a similar-looking address can be a scam.
Unlimited allowances are convenient, but they increase the damage from a compromised contract. Prefer the exact amount needed when the application supports it. For a one-time claim, consider revoking the allowance afterward.
Changing an existing allowance directly can create a race condition. If the old allowance is nonzero, set it to zero first, wait for confirmation, and then set the new amount. This is especially important when changing a large allowance.
Revoking an approval changes future permission. It cannot recover tokens that a spender already moved.
Signed messages and permit requests
A signature is not always harmless because it does not immediately create a blockchain transaction. Some token contracts support EIP-2612 permit signatures. A permit lets a spender submit your signed authorization later. Other systems, such as Permit2, can create a broader approval system where one contract manages permissions for many applications.
Read the wallet’s typed-data display. Check:
- The verifying contract address.
- The token and spender.
- The amount or permitted operations.
- The chain ID.
- The expiration time and nonce.
- Whether the message authorizes one action or future actions.
Reject messages that the wallet displays as unreadable, opaque, or unrelated to what you intended. A signature can authorize token transfers, NFT operations, or contract settings even when no transaction fee is requested.
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const token = new ethers.Contract(
process.env.TOKEN_ADDRESS,
["function approve(address spender, uint256 amount) returns (bool)"],
wallet
);
// Use zero to revoke an existing allowance for this spender.
const transaction = await token.approve(process.env.SPENDER_ADDRESS, 0n);
await transaction.wait();
console.log("Approval revoked:", transaction.hash);Store private keys only in a secure environment. Never paste a seed phrase or private key into a claim page, chat, or browser form.
A safer review sequence
- Stop if the request is unexpected or urgent.
- Identify the exact token, spender, chain, amount, and expiry.
- Compare the contract address with the project’s trusted documentation.
- Reject unlimited or permanent permissions unless you understand the trade-off.
- Use a separate wallet for experiments and untrusted claims.
- Review and revoke unused allowances through a reputable block explorer or approval manager.
Exercise
You approved a claim contract for an unlimited amount six months ago, but you no longer use the project. What should you do, and what can revocation not undo?
Show answer
Revoke the token allowance for that spender. Revocation prevents future transfers through that permission, but it cannot recover tokens the spender already moved.