Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wrightkhlebisol/dcce01aaf08443a183b3df1c55776038 to your computer and use it in GitHub Desktop.
Save wrightkhlebisol/dcce01aaf08443a183b3df1c55776038 to your computer and use it in GitHub Desktop.
pragma solidity ^0.5.0;
contract Base {
uint public num;
address public sender;
function setNum(uint _num) public {
num = _num;
sender = msg.sender;
}
}
contract FirstCaller {
uint public num;
function setBaseNum(address _base, uint _num) public{
Base base = Base(_base);
base.setNum(_num);
}
function callSetNum(address _base, uint _num) public {
(bool status, bytes memory returnData) = _base.call(abi.encodeWithSignature("setNum(uint256)", _num)); // Base's num is set
}
function delegatecallSetNum(address _base, uint _num) public {
(bool status, bytes memory returnData) = _base.delegatecall(abi.encodeWithSignature("setNum(uint256)", _num)); // Base's num is set
}
}
contract SecondCaller {
function callThrough(FirstCaller _fc, Base _base, uint _num) public {
_fc.delegatecallSetNum(address(_base), _num);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment