{"id":7073,"date":"2024-01-30T07:40:39","date_gmt":"2024-01-30T07:40:39","guid":{"rendered":"https:\/\/metaschool.so\/articles\/?p=7073"},"modified":"2025-01-16T08:09:24","modified_gmt":"2025-01-16T08:09:24","slug":"what-are-erc20-approve-erc20-allowance-methods","status":"publish","type":"post","link":"https:\/\/metaschool.so\/articles\/what-are-erc20-approve-erc20-allowance-methods\/","title":{"rendered":"ERC20 Approve and Allowance: Token Permissions in Ethereum"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_56_1 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/metaschool.so\/articles\/what-are-erc20-approve-erc20-allowance-methods\/#Overview\" title=\"Overview\">Overview<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/metaschool.so\/articles\/what-are-erc20-approve-erc20-allowance-methods\/#ERC20_approve_method\" title=\"ERC20 approve method\">ERC20 approve method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/metaschool.so\/articles\/what-are-erc20-approve-erc20-allowance-methods\/#ERC20_allowance_method\" title=\"ERC20 allowance method\">ERC20 allowance method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/metaschool.so\/articles\/what-are-erc20-approve-erc20-allowance-methods\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n<h2 class=\"wp-block-heading\" id=\"overview\"><span class=\"ez-toc-section\" id=\"Overview\"><\/span>Overview<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <a href=\"https:\/\/metaschool.so\/articles\/erc20-crypto-wallet-address\/\" target=\"_blank\" rel=\"noreferrer noopener\">ERC20<\/a> approve and ERC20 allowance methods allow you to give a specific <a href=\"https:\/\/metaschool.so\/articles\/what-is-a-smart-contract\/\" target=\"_blank\" rel=\"noreferrer noopener\">smart contract<\/a> permission to use a certain amount of their tokens, without giving control of the entire token balance. It&#8217;s like giving a friend permission to withdraw money from your account up to a certain limit without giving them total control of your funds.<\/p>\n\n\n\n<p>Let\u2019s look at each method with coding examples for better understanding.<\/p>\n\n\n\n<p><strong> \ud83d\udd25 Check this out:<\/strong> <a href=\"https:\/\/metaschool.so\/build-in-public\" target=\"_blank\" rel=\"noreferrer noopener\">Build in Public<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"erc20-approve-method\"><span class=\"ez-toc-section\" id=\"ERC20_approve_method\"><\/span>ERC20 approve method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>This method empowers a token holder to authorize a designated smart contract to spend a predefined quantity of tokens from their balance.<\/li><li>The ERC20 approve method enables token holders to selectively allow spending for specific purposes or transactions, enhancing the flexibility of token usage.<\/li><li>Token holders retain the ability to revoke or modify approvals granted through the approve method, providing dynamic control over the smart contracts they authorize.<\/li><li><strong>Function Signature:<\/strong> <code>function approve(address spender, uint256 amount) external returns (bool);<\/code><\/li><li><strong>Parameters: <\/strong>There are two parameters in ERC20 approve method<ul><li><strong><code>spender<\/code><\/strong>: The address of the permitted smart contract or any Ethereum address.<\/li><li><strong><code>amount<\/code><\/strong>: The maximum token amount the spender is permitted to use on behalf of the token holder.<\/li><\/ul><\/li><li><strong>Return Value:<\/strong> A boolean signaling the success of the approval.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code has-nv-site-bg-background-color has-background\" style=\"font-size:16px\"><code>function grantPermission(address spender, uint256 amount) external {\n  \/\/ Grant approval for the spender to utilize 'amount' tokens on behalf of the message sender\n  require(token.approve(spender, amount), \"Approval failed\");\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"erc20-allowance-method\"><span class=\"ez-toc-section\" id=\"ERC20_allowance_method\"><\/span>ERC20 allowance method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>This method provides the remaining token count that the spender can expend on behalf of the token holder.<\/li><li>The ERC20 allowance method facilitates real-time monitoring of the remaining spending capacity, allowing both token holders and smart contracts to stay informed about the available allowance.<\/li><li>Token holders can strategically allocate allowances to different smart contracts based on their purposes, optimizing resource distribution within the ERC20 ecosystem.<\/li><li><strong>Function Signature:<\/strong> <code>function allowance(address owner, address spender) external view returns (uint256);<\/code><\/li><li><strong>Parameters:<\/strong> There are two parameters in ERC20 allowance method<ul><li><strong><code>owner<\/code><\/strong>: The token holder&#8217;s address.<\/li><li><strong><code>spender<\/code><\/strong>: The address of the authorized smart contract or any Ethereum address.<\/li><\/ul><\/li><li><strong>Return Value:<\/strong> The remaining allowance (token count) available for the spender.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code has-nv-site-bg-background-color has-background\" style=\"font-size:16px\"><code>function checkAllowance(address owner, address spender) external view returns (uint256) {\n  \/\/ Retrieve the remaining allowance for 'spender' on behalf of 'owner'\n  return token.allowance(owner, spender);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>ERC20 allowance and approve methods allow users to set detailed permissions and ensure safe transactions in the ERC20 system.<\/li><li>Token holders can control how much smart contracts affect their tokens, providing a nuanced layer of control to <a href=\"https:\/\/metaschool.so\/articles\/building-a-dapp-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\">decentralized applications<\/a>. Knowing and using these methods is essential for effectively using ERC20.<\/li><\/ul>\n\n\n\n<p><strong>Tried this out? Let us know how it went by tagging Metaschool on your Social Media!<\/strong><\/p>\n\n\n\n<p><strong>Follow us on<\/strong> &#8211; <\/p>\n\n\n\n<p> \ud83d\udd2e Twitter &#8211; <a href=\"https:\/\/twitter.com\/0xmetaschool\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/twitter.com\/0xmetaschool<\/a><\/p>\n\n\n\n<p> \ud83d\udd17 LinkedIn &#8211; <a href=\"https:\/\/www.linkedin.com\/company\/0xmetaschool\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.linkedin.com\/company\/0xmetaschool\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":13,"featured_media":11072,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[292],"tags":[51,321,31,46,74,68],"class_list":["post-7073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-answers","tag-blockchain","tag-erc20","tag-ethereum-blockchain","tag-solidity","tag-web3-glossary","tag-web3-words"],"_links":{"self":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/7073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/comments?post=7073"}],"version-history":[{"count":20,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/7073\/revisions"}],"predecessor-version":[{"id":11888,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/7073\/revisions\/11888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media\/11072"}],"wp:attachment":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media?parent=7073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/categories?post=7073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/tags?post=7073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}