4

How can contract B (created and owned by contract A) verify that contract A invoked the kill method? (Is msg.sender the same for contract A and B or is msg.sender the address of contract A when A calls B)

stefreak
  • 155
  • 5
  • Related: http://ethereum.stackexchange.com/questions/1891/whats-the-difference-between-msg-sender-and-tx-origin – eth May 29 '16 at 04:22

1 Answers1

4

Yes, it can. If you write your contract as owned based in this other contract which I show here below (same as written in the ethereum.org token tutorial), it can.

contract owned {
    address public owner;

    function owned() {
        owner = msg.sender;
    }

    modifier onlyOwner {
        if (msg.sender != owner) throw;
        _
    }

    function transferOwnership(address newOwner) onlyOwner {
        owner = newOwner;
    }
}

If you want to make the original executor of the contract A the owner of the contract B you would only have to change owner = msg.sender;for owner = tx.origin, in the owned contract.

arodriguezdonaire
  • 3,027
  • 3
  • 20
  • 37
  • So in other words, when I initiate a transaction on contract A and A internally makes a sub-transaction on B, B will see A as msg.sender and not the original initiator of the transaction? – stefreak May 28 '16 at 20:43
  • Yes, the initiator of the transaction would be the tx.origin. – arodriguezdonaire May 28 '16 at 20:45