Token allowance and approvals
Token allowance and approvals: how to use them in a safe way

Token allowance and approvals

Have you ever heard about token allowance? Token allowance is like giving conditional access to your funds in DeFi without exposing your private keys. Think of it as a digital 'power of attorney' for your crypto. This opens a whole new world of opportunities but also risks.

Tokens on Ethereum have 'allowance' built-in, facilitating automated interactions with smart contracts. This function allows a private key to sign an allowance to be executed later if a condition is met. In other words, gives a Dapp your permission to spend tokens on your behalf.

Why do allowance functions exist? Giving access to spend our tokens is a necessary condition to perform transactions in DeFi that, in another way, would involve more steps because we would have first to send our tokens to a contract since the contract doesn′t have access to them.

As an example, a swap without token allowance would first consist of us users sending our tokens to the swap contract and then receiving them in a different transaction. It would not be an atomic transaction. Allowing DApps to access tokens under conditions boosts efficiency.

The 'allowance' function in ERC-20/ERC-777 is structured as 'allowance(address tokenOwner, address spender)'. It specifies how much a contract can use from your tokens. You can dive into technical aspects of the function in Open Zeppelin docs: https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#IERC20-allowance-address-address-

Technical details about Allowance in Open Zeppelin documentation

Types of Allowances - On-chain/Off-chain

On-chain allowances are recorded on the blockchain, offering transparency and traceability. They're immutable once set until you decide to change them. You pay gas fees when signing it.

On the other hand, Off-chain allowances bypass the blockchain for speed and lower costs. They rely more on trust and less on transparency. An off-chain allowance could be stored, waiting to be sent to the blockchain in the future through a relayer. Let's see a practical example:

Imagine using Compound to invest in a pool. You will need to manually allow the contract to access your tokens and compound your investment each time. Instead, you grant an 'allowance' for a specific token amount to Compound's contract. This automates your investment securely.

Editing spend limit permission in Metamask


Risks and Considerations Allowance functions are secure by design, providing limited, revocable access to your funds. Always scrutinize and consent to access requests for safety. Despite being secure, misuse of token allowances can pose risks.

Security measures: A good practice is to periodically revoke allowances in our wallets, tools like Etherscan approval checker, and https://revoke.cash are your friends. It’s a simple step for massive peace of mind. Control is in your hands!

With Etherscan, you can connect your wallet to their token approval checker, which will allow you to see approvals that have been signed with your wallet and easily revoke them https://etherscan.io/tokenapprovalchecker

Etherescan token approval checker

Also, allowances aren't a one-size-fits-all solution. You can set the exact amount a contract can use, adding another layer of control over your DeFi interactions.

The Case of Non-Fungible Tokens (NFTs) In contrast, NFTs like ERC-721 (think about Bored Apes) don't use allowances, as they represent unique, non-fungible items. Different tokens, different rules.

Token allowance is more than a feature. It ensures fluidity, security, and user autonomy in the rapidly evolving crypto world. Understanding token allowances empowers you to navigate DeFi with confidence and maximize your crypto experience safely and efficiently!

One of the most common scams is when a user is tricked into a phishing website impersonating a dapp, and after connecting their wallet, they are asked for approval to spend their tokens by a malicious smart contract that will drain the user's wallet immediately.

It's very important to check twice when making an approval, even if it's just a signature that is not paying for gas. Check both the web-site you are interacting with and the content of the signature or transaction before sending it. Tools like Blockfence check this for you.

What's your take on token allowances? Let us know what you think about this function, how confident you feel using it, and what other security measures can be applied. Follow us for more blockchain security tips & news Blockfence

要查看或添加评论,请登录

Blockfence的更多文章

社区洞察

其他会员也浏览了