In blockchain and Ethereum Request for Comment 20 (ERC-20) tokens, an allowance is a pre-approved spending limit that a token owner (owner) grants to another address (spender), enabling the spender to transfer a specified maximum amount of tokens from the owner's balance on their behalf. This mechanism is fundamental to decentralized finance (DeFi) and dApp interactions, as it allows protocols like decentralized exchanges (DEXs) or lending platforms to execute trades or repay loans without requiring the user to sign a new transaction for every single action, while maintaining a strict cap on risk exposure.
Allowance
What is Allowance?
A core security mechanism in tokenized ecosystems that controls delegated spending permissions.
The allowance system is implemented via two primary functions in the ERC-20 standard: approve() and transferFrom(). The owner calls the approve(spender, amount) function on the token's smart contract, authorizing the spender to withdraw up to the specified amount. Subsequently, the authorized spender can call transferFrom(owner, recipient, amount) to move tokens from the owner's wallet to a recipient, provided the transfer value does not exceed the remaining allowance. This creates a secure, non-custodial delegation model where the owner retains ultimate control over their funds.
Managing allowances is a critical security practice. Users must be cautious of unlimited allowances, where the approved amount is set to the maximum possible value (2^256 - 1), as this grants the spender contract perpetual access to the entire token balance, posing a significant risk if the spender's contract is compromised. Modern wallet interfaces and DeFi front-ends often recommend setting time-bound or transaction-specific limits. The related ERC-2612 permit() standard further enhances this model by allowing off-chain allowance approvals via cryptographically signed messages, improving user experience and reducing transaction fees.
How Does an Allowance Work?
An allowance is a core security and convenience mechanism in the ERC-20 token standard, enabling one Ethereum address to grant permission for another address to spend a specific amount of its tokens.
An allowance is a pre-authorized spending limit set by a token owner (the owner) for a third-party address (the spender), typically a smart contract like a decentralized exchange (DEX) or lending protocol. This is implemented via the approve function, where the owner specifies the spender address and the maximum token amount they are permitted to transfer on the owner's behalf. This delegation is essential because ERC-20 tokens are non-custodial; a smart contract cannot directly access tokens held in a user's wallet without explicit prior permission.
Once an allowance is granted, the spender can execute transfers up to the approved limit by calling the transferFrom function. This function checks the pre-set allowance, deducts the transfer amount from it, and moves the tokens from the owner to a recipient. A common use case is providing liquidity on a DEX: a user approves a router contract to spend their USDC, allowing it to swap those tokens for ETH within a single transaction. The allowance is a non-transactional on-chain record stored in the token contract's internal mapping, which can be queried by anyone using the allowance(owner, spender) view function.
Managing allowances involves important security considerations. Users should only approve trusted contracts and consider setting limits instead of infinite approvals (e.g., type(uint256).max). To modify an allowance, you must call approve again with a new amount; it is standard practice to first set it to zero before setting a new value to prevent certain front-running attacks. Revoking an allowance is done by calling approve with an amount of zero. This mechanism underpins countless DeFi interactions, enabling composability while maintaining user control over their assets.
Key Features of Allowances
An allowance is a pre-authorized spending limit a token holder grants to a smart contract or another address. This section details its core operational mechanics and security considerations.
ERC-20 Standard Interface
The approve and transferFrom functions are defined in the ERC-20 token standard. approve(spender, amount) sets the allowance, while transferFrom(sender, recipient, amount) is called by the spender to move tokens, deducting from the allowance. This standardized interface enables universal compatibility across wallets and DeFi protocols.
Infinite Approvals
A user can grant an allowance equal to the maximum uint256 value (2^256 - 1), effectively authorizing unlimited spending of that token. While convenient, this practice introduces significant security risk if the spender contract is compromised or malicious. Modern wallets often warn against or default to finite amounts.
Allowance Race Condition
A known vulnerability where changing an existing allowance is not atomic. If a user has an existing allowance of 100 tokens and wants to change it to 50, they must first set it to 0, then to 50. A malicious spender watching the mempool can front-run the zeroing transaction with a transferFrom for the original 100, draining the intended new limit.
ERC-2612: Permit for Gasless Approvals
An EIP-712 signed message (a permit) allows a user to approve a spender without sending an on-chain transaction. The spender submits the signature, paying the gas, and the allowance is set. This improves UX and enables gasless onboarding and batch transactions. It's a core feature of tokens like USDC and DAI.
Revocation and Management
Allowances persist until explicitly revoked or spent. To revoke, the token holder must call approve(spender, 0). Poor allowance management is a major security vector, as forgotten approvals to old or deprecated contracts can be exploited. Tools like revoke.cash help users monitor and manage active allowances across chains.
Use in DeFi Protocols
Allowances are foundational for non-custodial DeFi. Examples include:
- DEX Swaps: Approving a router (e.g., Uniswap, 1inch) to spend your tokens for a trade.
- Lending: Approving a lending pool (e.g., Aave, Compound) to collateralize your assets.
- Yield Farming: Approving a staking contract to lock your LP tokens. Each interaction requires a specific, finite allowance for the protocol's core contract.
Code Example: The `approve` and `allowance` Functions
A practical breakdown of the core smart contract functions that enable delegated token spending on the Ethereum blockchain.
In the ERC-20 token standard, the approve and allowance functions are the foundational mechanisms for enabling delegated token transfers. The approve function is called by a token owner (the msg.sender) to authorize a specific spender address to withdraw a set number of tokens from the owner's balance, up to a specified allowance. This creates a permission layer separate from direct ownership, which is essential for decentralized exchanges (DEXs), decentralized finance (DeFi) protocols, and gas-less transaction systems. The function signature is typically approve(address spender, uint256 amount).
The corresponding allowance function is a view function that allows anyone to query the current spending limit granted by one address (owner) to another (spender). Its signature is allowance(address owner, address spender) returns (uint256). This publicly readable on-chain record is critical for smart contracts to check permissions before executing a transfer on a user's behalf via the transferFrom function. Together, this trio of functions—approve, allowance, and transferFrom—form the allowance pattern, a cornerstone of interoperable Ethereum applications.
A critical security consideration is the allowance race condition. If a user has an existing allowance of 100 tokens for a spender and wants to change it to 50, they might call approve(spender, 50). However, if the spender sees the pending transaction, they could front-run it with a transferFrom call to use the old 100-token allowance before it's reduced, then receive the new 50-token allowance afterward. The recommended mitigation is to first set the allowance to zero before setting a new amount, or to use the safer increaseAllowance/decreaseAllowance functions introduced in later ERC-20 implementations.
Ecosystem Usage & Examples
An allowance is a pre-authorized spending limit granted by a token holder to a smart contract or another address. This mechanism is fundamental to DeFi, enabling secure, non-custodial interactions without repeatedly transferring ownership.
Lending & Borrowing Protocols
Platforms like Aave and Compound require allowances to deposit collateral or supply assets to their liquidity pools. Granting an allowance to the protocol's core contract lets it custody your tokens, minting a derivative (like aTokens or cTokens) in return. This is also required for flash loans, where the borrower must approve the repayment amount to the lending contract within the same transaction.
- Key Use: Enabling collateralization and yield generation.
- Risk: A malicious or exploited contract could drain funds up to the allowance limit.
ERC-20 Permit (EIP-2612)
The ERC-20 Permit standard eliminates the need for a separate approve transaction. Instead, users sign a structured message (EIP-712) offline, granting an allowance. The spender submits this signature to a contract, which can then execute the allowance and the subsequent action (e.g., a swap) in one transaction.
- Benefit: Saves gas, improves UX, and enhances security by avoiding front-running on the approval.
- Adoption: Used by tokens like USDC and DAI, and integrated into wallets like MetaMask.
NFT Marketplaces & Staking
For ERC-20 tokens used as currency (e.g., WETH, USDC), NFT marketplaces like OpenSea require an allowance to facilitate purchases. For ERC-721/ERC-1155 NFTs themselves, a different mechanism—setApprovalForAll or approve—is used to grant listing rights.
In NFT staking or yield farming, you grant an allowance to a staking contract for the LP tokens or NFTs you wish to deposit, allowing it to lock them on your behalf in exchange for rewards.
Infinite vs. Finite Approvals
Users often grant infinite (unlimited) allowances (e.g., 2^256 - 1) for convenience, eliminating the need for repeated approvals. However, this poses a significant security risk if the approved contract is compromised.
Finite allowances specify a exact maximum amount, offering better security but requiring more transactions. Best practices now encourage:
- Revoking unused allowances via
approve(spender, 0). - Using allowance management tools like revoke.cash to audit and reset permissions.
- Preferring permit signatures or gasless meta-transactions where possible.
Cross-Chain & Bridge Interactions
When using cross-chain bridges (e.g., Across, Hop), you grant an allowance to the bridge's deposit contract on the source chain. This allows it to take custody of your tokens, lock or burn them, and mint a representation on the destination chain.
Similarly, layer-2 rollups often require allowances for depositing funds into their bridge contracts (e.g., Arbitrum's L1GatewayRouter). The allowance mechanism ensures the bridge can only move the specific, user-authorized amount.
Security Considerations & Risks
An allowance is a permission granted by a token holder (owner) to another address (spender) to spend a specific amount of their tokens, a core mechanism enabling DeFi composability but introducing critical attack surfaces.
Spender Contract Vulnerabilities
The security of an allowance is only as strong as the spender contract it is granted to. A malicious or buggy spender can exploit its allowance beyond the user's intent. Common issues include:
- Logic flaws allowing unauthorized withdrawals.
- Upgradeable contracts where a malicious upgrade changes behavior.
- Centralization risks where the spender's owner has excessive control.
Users must audit or trust the spender's code and governance.
ERC-20 vs. ERC-721 Allowances
ERC-20 (fungible token) allowances grant a spending limit (uint256), while ERC-721 (NFT) allowances are typically granted for specific token IDs via approve() or for an operator to manage all NFTs via setApprovalForAll(). The risks differ:
setApprovalForAll: Grants sweeping control over all current and future NFTs in a collection, an extreme risk.- Specific
approve: Lower risk but still requires vigilance for the approved token ID.
NFT marketplaces commonly request setApprovalForAll for UX, creating significant exposure.
Comparison: Allowance vs. Other Permission Models
A technical comparison of on-chain methods for granting third-party contracts the ability to move a user's tokens.
| Feature / Characteristic | Allowance (ERC-20/ERC-721) | TransferFrom with Signature (EIP-2612/EIP-4494) | Delegate (e.g., Compound cTokens) | Direct Transfer (No Permission) |
|---|---|---|---|---|
Permission Granularity | Amount/Token ID specific | One-time, amount-specific | Full balance of specific asset | N/A |
On-Chain Transaction Required to Grant | ||||
User Experience (UX) for Granting | Requires wallet approval tx | Off-chain signature | Requires wallet approval tx | N/A |
Revocation Method | Set allowance to 0 | Signature expires or is invalid | Redeem delegated tokens | N/A |
Gas Cost to Grant Permission | ~45k gas | < 10k gas (for verifier) | ~65k gas | 0 gas |
Common Use Case | DEX swaps, NFT marketplaces | Gasless listings, meta-transactions | Lending protocol collateral | Direct peer-to-peer transfer |
Risk of Over-Permissioning | High (unlimited approvals) | Low (specific amount/expiry) | High (full balance exposure) | None |
Evolution Beyond ERC-20
The ERC-20 allowance mechanism is a foundational primitive for delegated spending, but newer standards have evolved to offer greater security, flexibility, and efficiency.
The ERC-20 Foundation
The ERC-20 standard introduced the canonical approve and allowance model, enabling a token holder to authorize a third-party spender (like a DEX) to transfer a specific amount of tokens on their behalf. This is stored in a mapping: allowance[owner][spender]. While revolutionary, its basic design has limitations, such as the need for separate approvals per spender and the risk of front-running with approve.
ERC-2612: Permit for Gasless Approvals
ERC-2612 (Permit) extends ERC-20 by allowing users to approve token spending via off-chain EIP-712 signed messages instead of on-chain transactions. A user signs a structured message containing the spender and amount, which the spender can then submit to the contract. This enables:
- Gasless onboarding: Users can interact with dApps without holding native gas tokens.
- Batch operations: Combine approval and action (like a swap) in a single transaction, improving UX and reducing costs.
ERC-777: Advanced Operator Controls
ERC-777 introduces the concept of operators—trusted entities authorized to send tokens on a user's behalf. Unlike ERC-20's fixed-amount allowance, operators can be authorized or revoked for all tokens. It also features:
- Hooks: Contracts can implement
tokensToSendandtokensReceivedfor granular control over transactions. - Backward Compatibility: ERC-777 tokens are also ERC-20 compliant. This standard provides more powerful delegation mechanics but requires careful implementation to avoid vulnerabilities.
ERC-1363: Payable Token for Callbacks
ERC-1363 defines a payable token standard that allows tokens to notify a receiving contract after a transfer, similar to how ETH payments work. It adds transferAndCall and approveAndCall functions. After a transfer, the token contract calls a specific function on the recipient, enabling:
- Atomic interactions: A single transaction can pay for a service and trigger its execution (e.g., buying an NFT).
- Simplified logic: Removes the need for separate
approveand subsequent call transactions, streamlining processes like subscription payments.
ERC-5827: Auto-Renewing Allowances
ERC-5827 introduces renewable allowances, where an approved spending limit automatically replenishes over time based on a defined rate. Instead of a static allowance amount, it sets parameters like:
- Max amount: The ceiling for the allowance.
- Recovery rate: How many tokens per second are added back to the available allowance.
This model is ideal for streaming payments, subscriptions, and delegated vault management, providing continuous authorization without frequent manual
approvetransactions.
ERC-3009: Transfer With Authorization
ERC-3009 generalizes the permit idea for direct transfers, not just approvals. A user can sign an authorization for a specific transfer (amount, recipient, deadline), which any party can then execute. Key features include:
- Meta-transactions: Enables gas abstraction for token transfers themselves.
- Replay protection: Uses a nonce per user to prevent signature reuse.
- Batch transfers: Multiple signed authorizations can be executed in one transaction. This standard decouples the signer from the transaction submitter, enabling sophisticated relay services.
Common Misconceptions About Allowances
Allowances are a fundamental but often misunderstood security mechanism in token standards like ERC-20. This section clarifies widespread inaccuracies to help developers and users manage permissions safely.
No, an allowance is a permission, not a transfer. It is a pre-authorization granted by a token owner (the owner) to a third-party address (the spender) to withdraw a specified maximum number of tokens from the owner's balance at a future time. The tokens remain in the owner's wallet until the spender executes an actual transfer via the transferFrom function. This creates a delegated spending capability without moving funds initially.
Frequently Asked Questions (FAQ)
A token allowance is a critical security and utility mechanism in blockchain applications, particularly those using the ERC-20 standard. These questions address common developer and user concerns.
A token allowance is a permission granted by a token holder (the owner) to a third-party smart contract or address (the spender) to spend a specific amount of their tokens on their behalf. This is a core feature of the ERC-20 token standard, enabling decentralized applications (dApps) like decentralized exchanges (e.g., Uniswap) or lending protocols (e.g., Aave) to interact with user funds without requiring the user to sign a transaction for every single action. The allowance is set by calling the approve function on the token contract, specifying the spender's address and the maximum amount they can withdraw.
Get In Touch
today.
Our experts will offer a free quote and a 30min call to discuss your project.