Last active
April 29, 2018 09:12
-
-
Save tomw1808/bc0557ea6de24d4fa99035cd017aaf9d to your computer and use it in GitHub Desktop.
Example of a contract calling another contract and exceptions are thrown. One time with a named contract call, another time with a low level function call with call.value()()
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.21; | |
contract A { | |
/** | |
* Example of a named contract call exception | |
*/ | |
function someAException() public { | |
B myContractB = new B(); | |
myContractB.myB(); | |
} | |
/** | |
* Example of address.call.value()() | |
* | |
*/ | |
function someABoolean() public { | |
B myContractB = new B(); | |
//attention here, the call will execute because call.value() only returns a boolean | |
bool successfulCall = address(myContractB).call.value(0 ether)(bytes4(keccak256("myB()"))); | |
if(!successfulCall) { | |
//something went wrong | |
} else { | |
//it worked | |
} | |
} | |
} | |
contract B { | |
function myB() public payable{ | |
require(msg.value == 1 ether); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment