I want to initialise an instance of a contract inside another contract on behalf of some address.
e.g. I have contracts A and B
contract A{
address owner;
constructor() public{
owner = msg.sender;
}
}
and I want to instantiate this contract inside B as follows
contract B{
A instance = new A(); // I'm talking about this instance
}
so, I want here is that the instance is created on behalf of the caller(either deployer of contract B or through some function).
i.e. The owner setup in the instance
of A is the caller.
How can I do so?
Clearer example
I have two contracts A & B, and I create an instance of contract A inside B.
Contract A has a function, say anyFunction().
contract B{
A instance;
function anotherFunction() public{
A.anyFunction();
}
}
If I call anotherFunction()
, how can I make it sure that the call made to function anyFunction()
is on behalf of the caller of anotherFunction()
, and not on behalf of contract B.
A
, just have it take the owner as a parameter. But there's (thankfully) no way to fake the value ofmsg.sender
.msg.sender
, but then you ask how. :-) It's hard to suggest other solutions to your problem because I don't know what you're actually trying to do.