This is used to call other contract method but any change in states happened in the caller contract not in the targeted contract.
//SPDX-License-Identifier: No-Idea!
pragma solidity >=0.4.16 <0.9.0;
contract A{
uint public num;
address public sender;
uint public value;
function setVars(address _contract, uint _num)public payable{
(bool success, bytes memory data)= _contract.delegatecall(
abi.encodeWithSignature("setVars(uint256)", num)
);
}
}
contract B{
uint public num;
address public sender;
uint public value;
function setVars(uint _num)public payable{
num = _num;
sender = msg.sender;
value = msg.value;
}
}