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
contract NumberInterface { | |
function getNum(address _myAddress) public view returns (uint); | |
} |
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
contract Sandwich { | |
uint private sandwichesEaten = 0; | |
function eat() internal { | |
sandwichesEaten++; | |
} | |
} | |
contract BLT is Sandwich { | |
uint private baconSandwichesEaten = 0; |
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
import "./someothercontract.sol"; | |
contract newContract is SomeOtherContract { | |
} |
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
contract Animal { | |
function walk() public returns (string memory) { | |
return "walking"; | |
} | |
} | |
contract Cat is Animal { | |
function run() public returns (string memory) { | |
return "running"; | |
} |
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
contract Example{ | |
function sayHiToVitalik(string memory _name) public returns (string memory) { | |
// Compares if _name equals "Vitalik". Throws an error and exits if not true. | |
// (Side note: Solidity doesn't have native string comparison, so we | |
// compare their keccak256 hashes to see if the strings are equal) | |
require(keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("Vitalik"))); | |
// If it's true, proceed with the function: | |
return "Hi!"; | |
} |
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
contract Example{ | |
mapping (address => uint) favoriteNumber; | |
function setMyNumber(uint _myNumber) public { | |
// Update our `favoriteNumber` mapping to store `_myNumber` under `msg.sender` | |
favoriteNumber[msg.sender] = _myNumber; | |
// ^ The syntax for storing data in a mapping is just like with arrays | |
} |
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
contract Example{ | |
// For a financial app, storing a uint that holds the user's account balance: | |
mapping (address => uint) public accountBalance; | |
} |
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
YourContract.IntegersAdded(function(error, result) { | |
alert("event fired") | |
}) |
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
contract Example{ | |
// declare the event | |
event IntegersAdded(uint x, uint y, uint result); | |
function add(uint _x, uint _y) public returns (uint) { | |
uint result = _x + _y; | |
// fire an event to let the app know the function was called: | |
emit IntegersAdded(_x, _y, result); | |
return result; |
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
contract Example{ | |
uint8 a = 5; | |
uint b = 6; | |
// throws an error because a * b returns a uint, not uint8: | |
uint8 c = a * b; | |
// we have to typecast b as a uint8 to make it work: | |
uint8 c = a * uint8(b); | |
NewerOlder