This file contains hidden or 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; | |
interface ERC20 { | |
function totalSupply() constant returns (uint _totalSupply); | |
function balanceOf(address _owner) constant returns (uint balance); | |
function transfer(address _to, uint _value) returns (bool success); | |
function transferFrom(address _from, address _to, uint _value) returns (bool success); | |
function approve(address _spender, uint _value) returns (bool success); | |
function allowance(address _owner, address _spender) constant returns (uint remaining); | |
} |
This file contains hidden or 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 Debugging { | |
uint[] private vars; | |
function assignment() public pure { | |
// allocates the memory first before assigning | |
// so we'll see 2 values in the stack first | |
// and then the assignment takes place |
This file contains hidden or 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; | |
library Strings { | |
function concat(string _base, string _value) internal | |
returns(string) | |
{ | |
// By default, the type is storage but the value returned by bytes() | |
// is a memory pointer so explicitely mention that | |
// In order to modify string, you need to convert it to bytes | |
// string stores the UTF-8 format which can have > 1 byte |
This file contains hidden or 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.22; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
address delegate; | |
uint vote; | |
} |
This file contains hidden or 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 DataTypes { | |
bool myBool = false; | |
// Integers | |
int8 myInt = -128; | |
uint8 myUInt = 255; | |
This file contains hidden or 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; | |
// Each contract has an ethereum address can be addressed by | |
// this | |
contract Transaction { | |
// Events can log what is passed to it | |
event SendLogger(address); | |
event ValueLogger(uint); |
This file contains hidden or 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; | |
// using Libraries | |
library IntExtended { | |
function Increment(uint self) returns (uint) { | |
return self + 1; | |
} | |
function Decrement(uint _self) returns (uint) { |
This file contains hidden or 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; | |
// Pure Virtual class | |
interface Regulator { | |
function checkValue(uint amount) returns (bool); | |
function loan() returns (bool); | |
} | |
// Inheriting Regulator | |
// Anyone can access this bank class, To restrict this |
This file contains hidden or 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; | |
// Pure Virtual class | |
interface Regulator { | |
function checkValue(uint amount) returns (bool); | |
function loan() returns (bool); | |
} | |
// Inheriting Regulator | |
contract Bank is Regulator { |
This file contains hidden or 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 MyFirstContract { | |
string private name; | |
uint private age; | |
// Can use var newName but that by default will take 256 bits | |
function setName(string newName) public { | |
name = newName; | |
} |