1

Tx.origin is an old way of utilizing the handling address behind msg.sender. But let's say I, as a user, am calling a contract and that contract calls a contract. Is there a way for contract B... to specifically only receive calls from only contract A, meaning, is there something in front of msg.sender like tx.origin is behind msg.sender.

Example

Me => Contract A => Contract B

Tx.origin => Msg.sender => ???

Is there a way for contract B to specify, "HEY, ONLY CONTRACT A CAN CALL ME" if I am making a call to contract A from the "me" address?

1 Answer 1

5

The only options you have are tx.origin and msg.sender. The tx.origin is the original EOA (Externally Owned Account) which sent the transaction, while msg.sender is the sender of the current (internal) transaction.

From a contract's point of view, msg.sender is always the previous contract or EOA in the call chain. So in the chain "EOA => ContractA => ContractB", in the context of ContractB the msg.sender is ContractA. In the context of ContractA the msg.sender is the EOA.

If the chain is "EOA => ContractA = ContractB => ContractC", there is no way for ContractC to know that there was ContractA in the middle.

1
  • Pardon my pedantry, but there is a way. It involves customisation. One could design a system such that ContractB lets ContractC know (through calldata) whether it was called by an EOA or by ContractA. Or ContractB could modify storage, which would be subsequently accessed by ContractC. Sep 10, 2021 at 14:32

Your Answer

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

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