ERC20Permit
In standard ERC20, users typically need to execute two separate transactions:
- Approval (approve): The user authorizes a certain amount of tokens to a recipient.
- Transfer (transferFrom): The recipient transfers tokens from the user's account.
This approach not only increases gas costs but also diminishes user experience. By using ERC20Permit, we can merge these two steps into a single transaction, thereby saving gas and simplifying the process.
Gas Optimization Comparison
Standard ERC20 Process
- User calls
approve(spender, amount)
: approximately 50,000 gas - Recipient calls
transferFrom(owner, recipient, amount)
: approximately 65,000 gas
Optimized Process Using ERC20Permit
- User generates a signature (off-chain operation, no gas cost)
- Recipient calls
transferWithPermit
(including permit and transferFrom): approximately 80,000 gas
Savings: approximately 35,000 gas, equivalent to a 30% gas reduction.