0

Here is the example for question.

contract example1 {
  function A() {
    print msg.sender; // just fake code to imagine it prints out the result
    example3.C();
  }
}

contract example2 {
  function B() internal {
    print msg.sender; 
  }
}

contract example3 is example2 {
  function C() {
    print msg.sender;
    B();
  }
}

If I call function A(), then A() will print my address, and C() will print contract example1's address. Then is B() will print contract example1's address or contract example2's address?

0

1 Answer 1

0

As per the Solidity docs:

When a contract inherits from other contracts, only a single contract is created on the blockchain, and the code from all the base contracts is compiled into the created contract.

which means code of example2 will be added in example3 and example3 will look like:

contract example3 {
  function C() {
    print msg.sender;
    B();
  }
function B() internal {
    print msg.sender; 
  }
}

So as mentioned here, c() will print example1's address twice.

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