Difference between msg.sender and tx.origin

Difference between msg.sender and tx.origin

In solidity security consideration, there is mention of tx.origin.

This blog explains about tx.origin in details and talk about when to use that.

As solidity developer, you need to be extra carefully when you create contract in solidity. If you do not consider this security recommendations then you may end up losing the money.

 

Recommendation to use tx.origin ?

Do not use tx.origin to check owner if there is nested calls between contracts as this refer to transaction origin contract not the one that calls the contract.

Confused and want to know the difference ?

We will make it more clear in this blog and make you aware the difference between msg.sender and tx.origin. You can go over the video to see it in more detail along with example.

below picture say all and show the difference between msg.sender and tx.origin.

difference_between_msg_send_and_tx_origin

 

In this example, contract a is calling contract b and in turn contract b is calling c like Contract A => Contract B => Contract C.

In contract c, msg.sender refer to contract B and tx.origin refer to contract A.

You should not use tx.origin to check the owner of the contract if there is nested calls between the contract and should be used considering it's purpose.

 

No Comments

Post a Reply

Inquire Now
close slider