hey @Kamil37,
The allowed mapping simply maps and address to an address to a number. We can use this to ‘map’ a token holders address to a spenders address to some amount, hence the spenders address now has a certain allowance that they are able to spend of msg.senders tokens.
allowed[msg.sender][_spender] = value
this double mapping forges a relationship between the msg.sender and some token spender. In other words when we approve using this approval function, we are allowing the token spender to spend a certain number of msg.senders tokens`. The amount that they are allowed to spend is dictated by the amount passed into the approve function.
However this alone does not mean anything. In order for this to actually have an effect we need to make a requirement in the transferFrom function. By making a requirement in the transfer functionFrom function that the spender must have a allowance value greater than the amount of tokens we are trying to send, ultimately allows us to restrict the _spender to only be able to transfer an amount of tokens that is dictated to how much we set via the approve function,.
For example say we approve addressB to be able to spend 1000 of AddressA’s tokens. We initialise it like so
allowed[AddressA][AddressB] = 1000
Now say we, as AdressB want to send some of AddressA’s tokens to someone. The we can use the trasnsferFrom function. So remember that our allowance is set to 1000. so if we call the transfer function and try to trasnfer 2000 tokens we will get an error because this exceeds our balance
function transferFrom(AddressB, AddressC, 2000) public returns .......
//including this requirment prevents us from spending above your allowance
require(allowed[AddressA][AddressB] >= value;
this will throw an error because we do not have a large enough allowance. So remember that the double mapping establishes a relationship between a two addresses and some value. msg.sender is the address with the tokens, address _spender is the address we are approving to spend msg.senders tokens and the value is the amount of tokens we permit the _sender to spend. Hope this makes sense