Skip to content

Instantly share code, notes, and snippets.

@yanglikun
Created August 7, 2018 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanglikun/b4741b98237c117eba609fb08d673f68 to your computer and use it in GitHub Desktop.
Save yanglikun/b4741b98237c117eba609fb08d673f68 to your computer and use it in GitHub Desktop.
smart_concrat_example.sol
pragma solidity ^0.4.0;
contract Counter{
uint public count=10;
function inc(uint num) public returns (uint){
return count+=num;
}
}
contract CallCounter{
uint public count=20;
function callByAddr(address addr) public returns(uint){
return Counter(addr).inc(2);
}
}
contract CallCounterByCall{
uint public count=20;
function callByAddr(address addr) public returns(bool){
bytes4 methodId=bytes4(keccak256("inc(uint256)"));
return addr.call(methodId,2);
}
}
contract CallCounterByDelegateCall{
uint public number=20;
function callByAddr(address addr) public returns(bool){
bytes4 methodId=bytes4(keccak256("inc(uint256)"));
return addr.delegatecall(methodId,2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment