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)

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.

  • 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

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.