Skip to content

Instantly share code, notes, and snippets.

View RFV's full-sized avatar

Riaan Francois Venter RFV

View GitHub Profile
@RFV
RFV / Gambling.sol
Created December 20, 2016 22:02
Solidity Gambling Smart Contract
contract Gamble {
function Gamble() {
owner = msg.sender;
address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2;
nameReg.callstring32string32("register", "UltimateGamble");
}
function gamble(uint luckyNumber) {
value = value+ msg.value;
hash randomness = sha3(block.prevhash ^ hash(msg.sender) ^ luckyNumber);
@RFV
RFV / CrowdFunding.sol
Created December 20, 2016 22:15
Crowdfunding Smart Contract
contract Crowdfunding {
address recipient; uint goal; uint deadline;
struct Contribution { address contributor; uint amount; }
Contribution[] contributions;
uint contributed;
function Crowdfunding(address _recipient, uint256 _goal, uint256 _deadline) {
recipient = _recipient;
goal = _goal;
deadline = _deadline;
}
@RFV
RFV / Ballot.sol
Created December 20, 2016 22:18
Ballot Smart Contract
contract Ballot {
enum Vote {
None,
Direct { proposal: Proposal },
Delegated { to: address }
}
struct Voter { vote: Vote; weight: uint; }
using Proposal = uint8;
chairperson: address;
numProposals: uint8;
@RFV
RFV / SimpleStorage.sol
Created December 20, 2016 22:19
Simple Storage Example Smart Contract
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
@RFV
RFV / Coin.sol
Created December 20, 2016 22:19
old coin contract implementation
contract Coin {
// The keyword "public" makes those variables
// readable from outside.
address public minter;
mapping (address => uint) public balances;
// Events allow light clients to react on
// changes efficiently.
event Sent(address from, address to, uint amount);
@RFV
RFV / AccessRestrictions.sol
Created December 20, 2016 22:20
Access Restriction Smart Contract function modifiers
contract AccessRestriction {
// These will be assigned at the construction
// phase, where `msg.sender` is the account
// creating this contract.
address public owner = msg.sender;
uint public creationTime = now;
// Modifiers can be used to change
// the body of a function.
// If this modifier is used, it will
@RFV
RFV / States.sol
Last active December 20, 2016 22:23
State Check Smart Contract function modifiers
contract StateMachine {
enum Stages {
AcceptingBlindedBids,
RevealBids,
AnotherStage,
AreWeDoneYet,
Finished
}
// This is the current stage.
Stages public stage = Stages.AcceptingBlindedBids;
@RFV
RFV / Purchase.sol
Created December 20, 2016 22:25
Esrcow system for purching goods
// This contract can be used to hold money while an item is in transit
// during purchase.
// This protocol is a variation of a protocol by Oleg Andreev which is
// described at
// https://gatecoin.com/blog/2015/10/blockchain2-disrupting-disrutors/
//
// Assume Bob wants to buy an item worth x Ether from Alice.
// Alice creates this contract and and sends 2x Ether to the contract
// together with its creation transaction.
// If Bob does not react, Alice can get her money back.
@RFV
RFV / DoubleOrNothing.sol
Created December 20, 2016 22:36
Double or Nothing betting smart contract with Bitcoin
contract Alarm {
function deposit();
function scheduleCall(address contractAddress, bytes4 abiSignature, bytes32
dataHash, uint targetBlock, uint8 gracePeriod);
}
contract BitcoinBridge {
function queuePayment(bytes bitcoinAddress) returns(bool successful);
}
@RFV
RFV / Ballot.sol
Created December 20, 2016 22:46
Voting with delegation Smart Contract
/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
// be used for variables later.
// It will represent a single voter.
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
address delegate; // person delegated to
uint vote; // index of the voted proposal