Question about chaining of Solidity constructors

Quick question. Given this Solidity code:

contract A {
       constructor(int x){}
}
contract B is A {
      constructor(int x) A(x) {}
}

Suppose the creator of B is address A1 (msg.sender when calling B constructor). When B calls A’s constructor, what is the msg.sender for A’s constructor? Is it address of B contract, or A1? In other words, is it an internal or external call.

Thanks!

1 Like

Hi @garbervetsky,

msg.sender for A's constructor when creating B is A1.

I tried it out quickly in Remix.

A.sol

pragma solidity ^0.5.0;

contract A {
    uint256 public value;
    address public who;
       constructor(uint256 x) public {
           value = x;
           who = msg.sender;
       }
}

B.sol

pragma solidity ^0.5.0;

import "./A.sol";

contract B is A {
      constructor(uint256 x) A(x) public {}
}
1 Like