Skip to content

Instantly share code, notes, and snippets.

@PJUllrich
Last active June 19, 2018 19:58
Show Gist options
  • Save PJUllrich/0a71071071d4406ebea83bbbcbc7536a to your computer and use it in GitHub Desktop.
Save PJUllrich/0a71071071d4406ebea83bbbcbc7536a to your computer and use it in GitHub Desktop.
Solidity Call, Callcode, Delegatecall Demo. Deploy contracts. Call functions and see how sender changes in either B, or C.
pragma solidity ^0.4.24;
contract A {
address public sender;
function dcall(B other, C child) public {
other.dcall(child);
}
}
contract B {
address public sender;
function cal(address other) public {
other.call(bytes4(keccak256("set()")));
}
function ccode(address other) public {
other.callcode(bytes4(keccak256("set()")));
}
function dcall(address other) public {
other.delegatecall(bytes4(keccak256("set()")));
}
}
contract C {
address public sender;
function set() public {
sender = msg.sender;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment