0

This part of own Q&A serial of posts which shares knowledge gained during work on one project

msg.sender brought some ambiguity to me as at the first look this is an address of user caller. However, when a approve another user's address to operate with my test token, contract that perform this operation failed to this and ended up as a reverted tx.

1 Answer 1

0

By using ether.js you could call contract.connect(<signer>) to change the context, in other words msg.sender address.

This signer should be a wallet/account, it could not be another contract. However when inside your contract this contract calls another contract msg.sender would be an address of the contract caller – not an address which was defined during the initial call, e.g. contract.connect(<signer>).

It might be important during ERC721 token approve call: we could approve one address, but eventually authorized ERC721 token function would be called by deployed contract which would end up with revered tx as this address has not been approved.

In short: msg.sender it is an address of contract caller - it would be a user's address who calls the contract or the contract's address who calls another contract despite on the origin caller is the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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