So I am using the open zeppelin erc20 simple token contract with no issues, but still can't grasp exactly what to do with allowance function. It seems that on more than one dapp 'helper' platform, you can just do a transfer of erc20 tokens from one address to another . So Allowance must not be for regular transfers right ? I would ultimately like to limit each user (address) to be able to send lets say no more than 20 tokens. Can I code this into the allowance function ? Will it get picked up automatically by the transfer function? I'm a bit confused here. what would I use the allowance function for ? All the docs seem to say either you have to use it first, or you can limit transferring amounts with the allowance function, but I'm stuck on this. Can somone please explain this in detail or give me a link that does ? Thanks in advance.
Allowance is when a smart contract wants to call
transferFrom on behalf of you. When you call
approve(), you're basically saying that you are giving permission to the spender (the smart contract) to take some tokens out of your wallet for you.
So is it the same thing as when you do the transfer, then the main contract address holder will have to click a button each time the transfer is done? No matter if it's from person A to person B and the contract holder is C , does C. have to click a button on metamask for example each time ? Or is there a way to code it in to the transfer ?
Nope, transfer doesn't use allowances. Transfer is transferring tokens from msg.sender's balance to a recipient. Everytime a user wants to make a transfer, they need to sign a transaction (click a button, sign metamask etc.)
I'm also just learning but as I can understand:
approve() you give permission to another account to use your funds.
This action will be done with
allowance() will say how much the other account can use from your funds.
Example: If I
approve() you to use 100, then
allowance() will be 100. Later, if you
transferFrom() 20 from my account then
allowance() will be 80.
As I told you, I'm just learning but I think that's how it goes.