I would like to clear my doubt that when caller and called contract are same. Then the memory will get a new initialization right? or is it a different case.
1 Answer
You can call your own contract's external functions (recursively) by this.functionName
. If you inspect msg.sender
in that subsequent call, the result is the that contract's address. Since it's an external call, a new memory range is allocated.
Here's an example:
pragma solidity ^0.8.0;
contract A {
event Addr(address);
function myA() view external returns (address) {
return msg.sender;
}
function test() public {
emit Addr(this.myA());
}
}
If you call the function test
, you see it emits the same contract address.