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.5.0; | |
contract A { | |
uint public a; | |
//A constructor set asinternalcauses the contract to be marked asabstract | |
constructor(uint _a) internal { | |
a = _a; | |
} | |
} |
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.5.0; | |
contract Sharer { | |
function sendHalf(address payable addr) public payable returns (uint balance){ | |
require(msg.value % 2 == 0, "Even value reqired."); | |
uint balanceBeforeTransfer = address(this).balance; | |
addr.transfer(msg.value / 2); | |
// Since transfer throws an exception on failure and | |
// cannot call back here, there should be no way for us to | |
// still have half of the money. |
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.23 <0.6.0; | |
contract C { | |
uint[] data; | |
function f() public pure returns(uint, bool, uint){ | |
return (7, true, 2); | |
} | |
function g() public { |
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 <0.6.0; | |
contract UnitExample { | |
function test() public { | |
assert(1 wei == 1); | |
assert(1 szabo == 1e12); | |
assert(1 finney == 1e15); | |
assert(1 ether == 1e18); | |
//The suffix years has been removed in version 0.5.0 due to:: |
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 <0.6.0; | |
contract ConversionExample { | |
function test() public { | |
int8 y = -3; | |
uint x =uint(y); //0xfffff..fd | |
uint32 a = 0x12345678; | |
uint16 b = uint16(a);// b will be 0x5678 now | |
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 <0.6.0; | |
contract DeleteExample { | |
uint data; | |
uint[] dataArray; | |
function f() public { | |
uint x = data; | |
delete x; //sets x to 0, does not affect data | |
delete data; // sets data to 0, does not affect x | |
uint[] storage y = dataArray; |
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 <0.6.0; | |
/// @dev Models a uint -> uint mapping where it is possible to iterate over all keys. | |
library IterableMapping | |
{ | |
struct itmap | |
{ | |
mapping(uint => IndexValue) data; | |
KeyFlag[] keys; | |
uint size; | |
} |
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.11 <0.6.0; | |
contract CrowFunding { | |
// Defines a new type with two fields | |
struct Funder { | |
address addr; | |
uint amount; | |
} | |
struct Campaign { | |
address payable beneficiary; | |
uint fundingGoal; |
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 <0.6.0; | |
contract C { | |
uint[] x; | |
// the data location of x is storage | |
// the data location of memoryArray is memory | |
function f(uint[] memory memoryArray) public{ | |
x = memoryArray; // works, copies the whole array to storage | |
uint[] storage y = x; // works, assigns a pointer, data location of y is storage | |
//y[7]; // fine, returns the 8th element | |
//y.length = 2; // fine, modifies x through y |
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.16 <0.6.0; | |
contract Oracle{ | |
struct Request{ | |
bytes data; | |
function(uint) external callback; | |
} | |
Request[] requests; | |
event NewRequest(uint); | |
event Reply(uint); |
NewerOlder