Created
August 7, 2018 13:31
-
-
Save yanglikun/b4741b98237c117eba609fb08d673f68 to your computer and use it in GitHub Desktop.
smart_concrat_example.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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