Skip to content

Instantly share code, notes, and snippets.

@Godtide
Forked from ConsenSys-Academy/ContextSwitcher.sol
Created November 6, 2019 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Godtide/efdd55f15b9640d4f21763ed4a4165e6 to your computer and use it in GitHub Desktop.
Save Godtide/efdd55f15b9640d4f21763ed4a4165e6 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