// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 < 0.9.0;
contract Receiver{
function getAddress() public view returns(address){
return address(this);
}
}
contract Caller{
Receiver receiver;
constructor(){
receiver = new Receiver();
}
function getAddress() public view returns(address){
return receiver.getAddress();
}
}
My question is: when testing the above code on Remix, I couldn't get the same address, why? here is the ss:
many thanks!
Here is the catch: The
newkeyword deploys and creates a new contract instance. in Caller's contract's constructor you are actually deploying a new instance ofReceiver. I add another function to get the deployedReceiverinstanceyou do not have to deploy
Receivercontract on remix.Callerwill already deploy a new contract. in the above both functions inCallerreturns same result: