I was trying to create a new contract from another one like this:
pragma solidity ^0.4.8;
contract Child {
address public owner;
function Child() public {
owner = msg.sender;
}
}
contract Parent {
address owner;
event NewChildCreated(address childAddress, address creator);
function Parent() public {
owner = msg.sender;
}
function createChild() public {
Child child = new Child();
NewChildCreated(address(child), child.owner());
}
}
So in remix I called createChild()
from the Parent
and there is a log with the address of that newly-created Child
contract (e.g. 0x1234
).
However, when I copied that address and created a Child
instance based on that address (0x1234
) in remix, I was not able to access the owner
property of it. I was getting this error: call to Child.owner errored: Cannot read property 'length' of undefined
.
Am I creating the child contract wrongly? Why I cannot refer to the newly-created Child contract?
ganache
. – user19510 Mar 1 '18 at 21:58