-
What is the difference between msg.senderand tx.originand why is it dangerous to use tx.origin? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
msg.sender: Refers to the address that called the function (can be a contract or a user). Solution : Always use msg.senderto verify caller ID. |
Beta Was this translation helpful? Give feedback.
msg.sender: Refers to the address that called the function (can be a contract or a user).
tx.origin: Refers to the address of the user who initiated the transaction (does not change, even if multiple contracts are called).
Problem withtx.origin : It exposes the contract to phishing attacks . An attacker can create a contract that calls your contract with tx.origin, thus exploiting the verification logic.
Solution : Always use msg.senderto verify caller ID.