0

I read ERC20 solidity code below.

https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC20/ERC20.sol

Then, I couldn't understand what the terms of msg.sender, spender, from, to, owner mean.

I guessed msg.sender equals from, spender equals to, and msg.sender equals owner. But if this hypothesis is true, allowed[from][msg.sender] isn't well defined.

I searched deeply but I couldn't get any information mentioned about above. Could anyone describe the definition and usage?

0

msg.sender is always the account that called the function. So any time you're reading code and see msg.sender, think "caller."

The caller is logically different entities depending on what function you're looking at. In the constructor, msg.sender is the account creating the contract (the "owner"). In a call to transfer, the caller is the owner of the coins being transferred, etc.

  • In transfer(to, amount), tokens are transferred from msg.sender to to.
  • In transferFrom(from, to, amount), msg.sender is the "spender" of tokens that are being transferred from from to to.
  • In allow(spender, amount), msg.sender is authorizing spender to be able to call transferFrom later.
  • In allowed[from][msg.sender], we're checking how many tokens from has previously allowed msg.sender to spend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.