0

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?

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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