3

In Solidity, origin and sender can be easily differentiated through tx.origin and msg.sender, respectively.

Is it also possible to obtain both sender and origin of a specific transaction from the data in blockchain itself? The from field obtained with getTransaction and getTransactionReceipt seems to always be tx.origin.

Specifically, I would like to do so with the JS API. I suspect that somehow processing the information in the transaction logs in the transaction's receipt is probably one way to go, but haven't figured out how yet (although I would expect some simpler way, too).

1 Answer 1

2

TLDR: There is no easy way or API to get the msg.sender for (internal) message calls.

In the Ethereum protocol there's only transactions and message calls. A transaction is a type of message call, and both tx.origin and msg.sender will always be the value of the from field.

A transaction may perform other message calls, but these are not transactions (even though a popular blockchain explorer labels them inaccurately as "internal transactions"). These (internal) message calls are not published on the blockchain, so there is no easy way or API to get their msg.sender. To find out how contracts call each other, the transaction needs to be processed through the EVM (for example, https://github.com/ethereumjs/ethereumjs-vm).


If you are the author of the contracts, every time a contract gets invoked, it could use an event to emit the value of msg.sender, and then you would be able to use getTransactionReceipt and parse the logs.

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.