Skip to content

Instantly share code, notes, and snippets.

View alexroan's full-sized avatar

Alex Roan alexroan

View GitHub Profile
@alexroan
alexroan / AccessModifiers.sol
Created March 24, 2020 12:34
examples/solidity-access-modifiers
pragma solidity >=0.5.0;
contract AccessModifiers {
// Public modifer exposes a getter for state variable
string public myString;
// Private variable only accessible within contract
string private myPrivateString;
// Internal functions can only be used within this contract
function innerFunction() internal {}
@alexroan
alexroan / RequireStatements.sol
Last active March 24, 2020 12:39
examples/solidity-require-statements
pragma solidity >=0.5.0;
contract RequireStatements {
function someFunction(address _anAddress) external {
// Require that the address given as a parameter is not equal to an empty addess.
// If the address is empty, the whole transaction will not be completed and will be reverted
require(_anAddress != address(0), "Not a valid address");
...
}
@alexroan
alexroan / CustomModifiers.sol
Created March 24, 2020 14:32
examples/solidity-custom-modifiers
pragma solidity >=0.5.0;
contract CustomModifiers {
// State variable
address private owner;
// Custom modifier requiring that the sender of the transaction is the owner
// otherwise revert the transaction
modifier onlyOwner {
@alexroan
alexroan / Mappings.sol
Last active March 24, 2020 14:42
examples/solidity-mappings
pragma solidity >=0.5.0;
contract Mappings {
// State variable
mapping(address => uint) public myMapping;
// Store a new value in the mapping
function putThing(address _key, uint _value) public {
myMapping[_key] = _value;
@alexroan
alexroan / Structs.sol
Last active March 24, 2020 15:21
examples/solidity-structs
pragma solidity >=0.5.0;
contract Structs {
// Define the Person struct
struct Person {
string name;
uint8 age;
}
@alexroan
alexroan / Inheritance.sol
Created March 24, 2020 15:30
example/solidity-inheritance
pragma solidity >=0.5.0;
contract Vehicle {
}
contract Car is Vehicle {
}
@alexroan
alexroan / Ethermon.sol
Created March 27, 2020 14:46
ethermon.sol@1
pragma solidity ^0.5.5;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract Ethermon is ERC721 {
}
@alexroan
alexroan / 2_deploy_contracts.js
Created March 27, 2020 14:53
ethermon/deploy_contracts.js@1
const Ethermon = artifacts.require("Ethermon");
module.exports = function(deployer) {
deployer.deploy(Ethermon);
};
@alexroan
alexroan / Ethermon.sol
Created March 27, 2020 15:19
ethermon.sol@2
pragma solidity ^0.5.5;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract Ethermon is ERC721 {
struct Monster {
string name;
uint level;
}
@alexroan
alexroan / Ethermon.sol
Created March 27, 2020 15:49
etheremon.sol@3
pragma solidity ^0.5.5;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract Ethermon is ERC721 {
struct Monster {
string name;
uint level;
}