I'm new on ERC20. I try to understand to code on ERC20 by see the source code in openzeppelin. However, I have some questions about implementation on relation between _allowances field, allowance method and _approve method in such a way that I might misunderstood something.
Questions
allowance - this method doesn't have amount as input parameter. Does it allow to withdraw without limitation?
If yes, I will curious more because _allowances field will keep to amount at the end. That's mean it has limitation or not?
As I could see it on _approve method.
Line 318 -> _allowances[owner][spender] = amount;
If no from 1,
Why does it need to keep amount on Line 318?
Why does ERC20 not change to be?
Can we merge allowance method and approve method to be approveOnce/allowOnce(address owner, address spender, uint256 amount).
Thank you for your answer.
Sorry, I don't want to bother you. However, I re-read those description, I still have questions.
Why does ERC20 really need to have "allowance" method?
What is the real situation usage that's ERC20 need this method?
function allowance(address owner, address spender) external returns (uint256);
For example, Alice call DAI.approve(Bob_Address, 100), then you can have a check, what is the approval amount given to Bob by Alice, that is DAI.allowance(Alice_Address, Bob_Address). So the result of this function mean how many you can withdraw.
Actually, function allowance is the result of the function approve, and why you need function approve, cause you want to use the function transferFrom.
In most cases, it is used in the contract. Eg, there is a lending protocol: Compound, you can deposit your DAI into it to earn interests, so for the contract, it should know you really deposit DAI and the amount when you deposit, here comes transferFrom. Contracts transfer tokens from user to itself via this function, but when you use transferFrom, you should call approve at first, and for the result, you can check by allowance, hope I made myself clear.