Loading live crypto data...
Education13 min read

SMARTCONTRACT Field Guide: What Actually Happens When You "Approve" a Contract

That "Approve" button in your wallet isn't just clicking OK. It's writing a permanent record on the blockchain that gives a contract permission to move your tokens. Here's exactly what happens under the hood, why it matters, and how to stay safe.

TLDR

  • Approving a contract writes an "allowance" to the blockchain that lets the contract spend your tokens
  • The approval transaction doesn't move tokens yet - it just grants permission for future transactions
  • Unlimited approvals (type(uint256).max) are convenient but risky if the contract is compromised
  • Approvals persist until you revoke them or spend the full allowance amount
  • Always verify contract addresses and use limited approvals when possible

By William S. · Published November 1, 2025

The Basics: Why Approvals Exist

Back in the early days of Ethereum, someone realized a problem: if you want to swap tokens on a DEX, you need to give the DEX contract permission to take your tokens first. But you don't want to give it your entire balance every time you swap.

The ERC-20 standard solved this with the approve() function. It's like giving someone a credit card with a spending limit - they can charge up to that amount, but no more.

Here's the thing most people miss: when you click "Approve," you're not sending tokens anywhere. You're writing a permission slip on the blockchain that says "Contract X can spend up to Y amount of my tokens."

What Happens On-Chain: Step by Step

Step 1: You Initiate the Approval

You're on Uniswap, trying to swap 100 USDC for ETH. Uniswap's interface calls your wallet (MetaMask, etc.) and says "Hey, I need permission to spend your USDC."

Your wallet shows you a popup: "Approve USDC spending cap?" with options like "Use default" (unlimited) or "Set custom limit" (100 USDC).

Step 2: The Transaction Gets Created

When you click approve, your wallet creates a transaction that calls the approve() function on the USDC token contract. The transaction includes:

  • To: The USDC token contract address (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
  • Function: approve(address spender, uint256 amount)
  • Parameters: The contract you're approving (Uniswap router) and the amount (or unlimited)
  • Gas: You pay gas fees for this transaction

Step 3: The Contract Updates Its Internal State

When your transaction gets mined, the USDC contract executes the approve() function. Inside the contract, there's a mapping that looks like this:

mapping(address => mapping(address => uint256)) public allowance;

// After your approval:
allowance[yourWallet][uniswapRouter] = 100000000; // 100 USDC (6 decimals)

This mapping stores: "Your wallet has given Uniswap permission to spend up to 100 USDC."

This data is now permanently stored on the blockchain. Anyone can query it. It doesn't expire. It stays there until you revoke it or the contract spends it all.

Step 4: The Approval Event Gets Emitted

The contract emits an Approval event that includes:

  • Your wallet address (owner)
  • The contract you approved (spender)
  • The amount approved (value)

This event is logged on the blockchain and can be read by anyone. It's how block explorers like Etherscan know to show your approvals.

Step 5: The Actual Swap Happens (Separate Transaction)

Now that you've approved, you can swap. When you click "Swap," Uniswap's contract calls the USDC contract's transferFrom() function.

The transferFrom() function checks:

  1. Do you have enough USDC? (Yes, you have 100+)
  2. Is the allowance sufficient? (Yes, you approved 100)
  3. If both are true, it transfers 100 USDC from your wallet to Uniswap
  4. It reduces your allowance: allowance[yourWallet][uniswapRouter] = 0

Notice: if you approved unlimited (type(uint256).max), the allowance stays at max even after the transfer. That's why unlimited approvals are risky - they never decrease.

Understanding Allowances

Limited vs Unlimited Approvals

When you approve, you set an allowance. This is the maximum amount the contract can spend.

Limited Approval

You approve exactly what you need: approve(uniswapRouter, 100000000) for 100 USDC.

Pros:

  • Safer - even if the contract is compromised, it can only take the approved amount
  • Self-limiting - once spent, the allowance is gone

Cons:

  • You need to approve again for each transaction
  • Extra gas costs for multiple approvals

Unlimited Approval

You approve the maximum possible value: approve(uniswapRouter, type(uint256).max) which equals 2^256 - 1 (an impossibly large number).

Pros:

  • Convenient - approve once, use forever
  • Lower gas costs over time

Cons:

  • If the contract gets hacked, your entire balance can be drained
  • The approval never expires or decreases
  • You might forget you approved it

I've been in crypto since 2010, and I'll tell you: unlimited approvals are fine for contracts you absolutely trust (Uniswap, Aave, Compound), but be careful with new or unknown contracts. I've seen too many people lose everything because they approved some random contract.

How Allowances Decrease

When a contract uses transferFrom() to spend your tokens, it reduces the allowance by the amount spent.

Example: You approve 1000 USDC. Contract spends 100 USDC. Remaining allowance: 900 USDC.

Exception: Unlimited approvals don't decrease. They stay at max forever, which is why they're dangerous.

The Security Implications

What Can Go Wrong

Approvals are powerful, and that power can be abused:

1. Malicious Contracts

A scam contract might look legitimate but drain your wallet the moment you approve it. Some contracts have hidden functions that transfer your tokens immediately after approval.

Protection: Always verify contract addresses match official sources. Use tools to read contracts before approving.

2. Compromised Contracts

Even legitimate contracts can be hacked. If Uniswap's router got compromised (hypothetically), anyone with unlimited approvals could lose everything.

Protection: Use limited approvals when possible. Revoke unused approvals regularly.

3. Phishing Sites

Scammers create fake sites that look like Uniswap but use different contract addresses. You approve thinking it's safe, but you've approved a malicious contract.

Protection: Always check URLs. Bookmark official sites. Verify contract addresses on Etherscan.

4. Approval Front-Running

In rare cases, if you approve a malicious contract, bots can see the approval transaction in the mempool and front-run it to drain your wallet before you realize what happened.

Protection: Don't approve unknown contracts. If you must, use limited approvals and revoke immediately after.

Managing Your Approvals

Checking Existing Approvals

You can see all your token approvals using:

  • Revoke.cash - Connect wallet, see all approvals, revoke with one click
  • DeBank - Portfolio tracker that shows approvals
  • Etherscan - Search your address, check "Token Approvals" tab

Revoking Approvals

To revoke an approval, you approve the same contract with amount 0:

approve(contractAddress, 0)

This sets the allowance to zero, effectively revoking the permission. You'll pay gas for this transaction, but it's worth it to reduce risk.

Best practice: Review your approvals monthly. Revoke ones you're not using. Keep only what you need active.

Setting Approval Limits

When approving, calculate what you actually need:

  • One-time swap: Approve exactly that amount
  • Regular trading: Approve 2-3x your typical trade size
  • Yield farming: Approve what you're depositing, not your entire balance

Remember: you can always approve more later. You can't undo an unlimited approval without revoking it (and paying gas).

Technical Deep Dive: The approve() Function

Here's what the standard ERC-20 approve function looks like:

function approve(address spender, uint256 amount) 
    public 
    virtual 
    returns (bool) {
    address owner = _msgSender();
    _approve(owner, spender, amount);
    return true;
}

function _approve(
    address owner,
    address spender,
    uint256 amount
) internal virtual {
    require(owner != address(0), "ERC20: approve from zero address");
    require(spender != address(0), "ERC20: approve to zero address");

    _allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
}

Key points:

  • _allowances is the mapping that stores approvals
  • The function emits an Approval event for transparency
  • It doesn't check if you have enough tokens - it just sets the allowance
  • The actual token transfer happens later via transferFrom()

Common Mistakes to Avoid

1. Approving Without Checking

Don't just click approve without verifying the contract address. Always check it matches the official project.

2. Unlimited Approvals for Unknown Contracts

Never approve unlimited for contracts you don't fully trust. Use limited approvals and increase if needed.

3. Forgetting About Old Approvals

Old approvals don't expire. If you approved a contract years ago and forgot about it, it's still active. Review and revoke regularly.

4. Approving on Phishing Sites

Always verify you're on the real site. Check the URL, bookmark official sites, never click links in emails or messages.

5. Not Understanding What You're Approving

If you don't understand what a contract does, don't approve it. Take time to research. Your tokens are worth protecting.

Real-World Example: Uniswap Swap

Let's trace through a complete example:

  1. You want to swap 50 USDC for ETH on Uniswap
  2. Uniswap requests approval for USDC
  3. You approve 50 USDC (limited approval)
  4. Transaction gets mined: allowance[yourWallet][uniswapRouter] = 50000000 (50 USDC)
  5. You click "Swap"
  6. Uniswap calls transferFrom(yourWallet, uniswapPool, 50000000)
  7. USDC contract checks: allowance sufficient? Yes. Balance sufficient? Yes.
  8. Contract transfers 50 USDC, reduces allowance to 0
  9. Uniswap sends you ETH
  10. Swap complete. Your approval is now used up (allowance = 0)

If you had approved unlimited, step 10 would be different: allowance stays at max, ready for your next swap without re-approving.

Best Practices Summary

  • Verify first: Always check contract addresses match official sources
  • Use limited approvals: Approve only what you need, when possible
  • Review regularly: Check your approvals monthly using Revoke.cash
  • Revoke unused: Remove approvals for contracts you're not using
  • Understand the contract: Read contracts or use trusted tools before approving
  • Start small: Test with small amounts before larger approvals
  • Bookmark official sites: Avoid phishing by using bookmarks, not links

Approvals are a necessary part of using DeFi, but they come with real risks. Understanding what happens when you approve helps you make better decisions and protect your assets. Stay safe out there.

Frequently Asked Questions

Do approvals expire?

No. Approvals don't expire. They persist until you revoke them (approve with amount 0) or the contract spends the full allowance. Unlimited approvals never decrease, so they stay active forever unless revoked.

Can I approve multiple contracts for the same token?

Yes. Each approval is separate. You can approve Uniswap for 100 USDC and Aave for 200 USDC simultaneously. Each contract has its own allowance that doesn't affect the others.

What happens if I approve more than I have?

The approval succeeds, but the contract can only spend what you actually have. If you approve 1000 USDC but only have 100, the contract can only take 100. The approval amount is a limit, not a guarantee of available funds.

Can I change an approval without revoking first?

Yes. Approving a new amount overwrites the previous approval. If you approved 100 USDC and then approve 200 USDC, the new allowance is 200. You don't need to revoke first, but revoking (approve with 0) is clearer if you want to remove the approval entirely.

Why do some contracts require unlimited approvals?

Some contracts (like older versions of Uniswap) were designed to require unlimited approvals for gas efficiency. However, you can often use limited approvals anyway - the contract will just ask you to approve again for subsequent transactions. Modern contracts usually support both.

Can a contract spend my tokens without my approval?

No, not if the token follows the ERC-20 standard correctly. The transferFrom() function checks allowances before transferring. However, malicious contracts might trick you into approving them, or there could be bugs in non-standard token implementations. Always verify contracts before approving.

By William S. · Published November 1, 2025

William was among the first to recognize Bitcoin's potential in its earliest days. That early conviction has grown into over a decade of hands-on experience with smart contracts, DeFi protocols, and blockchain technology. Today, he writes plain-English guides to help others navigate crypto safely and confidently.

Educational content only. This is not financial, legal, or tax advice.

Questions or corrections? Contact [email protected].

Join the Discussion

Have questions or thoughts? Share them below. All comments are moderated to prevent spam. Read our comment policy.