One of the limitations in the design of ERC20 tokens is the dynamic between approve
and transferFrom
. If one is interacting with a smart contract, it would require two transactions, one for approval and another for the smart contract call, which internally calls transferFrom
. Additionally, it also means that the user needs to have ETH to pay for the transaction fees.
To overcome this limitation, EIP-2612 offers a new methodology to circumvent these issues with a "permit" function on top of the ERC20 standard. This function enables users to alter the ERC20 allowance mapping using a signed message rather than via a direct call that they would have to conduct themsevles. This signed message is then used by another party (usually the spender on behalf of the owner) to call permit, which internally calls the allowance function. The off-chain signature generation and verification process is outlined via EIP-712 a standard that is widely supported by most of the major RPC providers.
-
Deploy the ERC20 permit contract (preferably remix for ease of interaction)
-
put in src/Main/main.js -> contractAddress state in main component
-
in src/Main/main.js -> chain id state to the chain the contract is deployed on (goerli is 5)
-
in src/Main/main.js -> Change name state to the deployed token name
-
npm start
to launch the web app (need metamask or an equivalent installed) -
Click connect and link the desired account you would like to sign for
-
Pass in the prompted values when you click sign
(spender, value, nonce, deadline)
thenonce
is the amount of total calls to this contract thus far for each specific address (included to avoid replay attacks) -
Follow the metamask prompts and complete the signing process
- Plug in the returned values (will appear in a prompt) into the deployed contract's permit function (any address can call this, as long as the passed in values compute to generate the signature of what the user signed off on)
- If the transaction is successful check the allowance view function to see if the spender has been approved for the amount specified