Created
January 11, 2018 10:36
-
-
Save anonymous/47de8bd36a5d0d04730a46a2f9b27e39 to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.19+commit.c4cbbb05.js&optimize=false&gist=
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.19; | |
contract RequestForTruth { | |
address admin; | |
function RequestForTruth() public { | |
admin = msg.sender; | |
} | |
} |
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; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
function Ballot(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public constant returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
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.18; | |
contract Courses { | |
struct Instructor { | |
uint age; | |
string fname; | |
string lname; | |
} | |
mapping (address => Instructor) instructors; | |
address[] public instructorAccts; | |
function setInstructor(address _address, uint _age, string _fName, string _lName) public { | |
var instructor = instructors[_address]; | |
instructor.age = _age; | |
instructor.fName = _fName; | |
// instructor.lName = _lName; | |
// instructorAccts.push(_address) -1; | |
} | |
function getInstructors() view public returns(address[]) { | |
return instructorAccts; | |
} | |
} |
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.18; | |
contract Coursetro { | |
string fName; | |
uint age; | |
address owner; | |
function Coursetro() public { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
event Instructor( | |
string name, | |
uint age | |
); | |
function setInstructor(string _fName, uint _age) onlyOwner public { | |
fName = _fName; | |
age = _age; | |
Instructor(_fName, _age); | |
} | |
function getInstructor() public constant returns (string, uint) { | |
return (fName, age); | |
} | |
} |
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.19; | |
contract Greeter { | |
address creator; | |
string greeting; | |
function Greeter(string _greeting) public { | |
creator = msg.sender; | |
greeting = _greeting; | |
} | |
function greet() public constant returns (string) { | |
return greeting; | |
} | |
function getBlockNumber() public constant returns (uint) { | |
return block.number; | |
} | |
function setGreeting(string _newgreeting) public { | |
greeting = _newgreeting; | |
} | |
function kill() public { | |
if (msg.sender == creator) | |
selfdestruct(creator); | |
} | |
} |
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
// https://learnxinyminutes.com/docs/solidity | |
pragma solidity ^0.4.19; | |
/// @title SimpleBank | |
/// @author nemild | |
contract SimpleBank { | |
mapping (address => uint) private balances; | |
address public owner; | |
event LogDepositMade(address accountAddress, uint amount); | |
function SimpleBank() public { | |
owner = msg.sender; | |
} | |
/// @notice Deposit ether into bank | |
/// @return The balance of the user after the deposit is made | |
function deposit() public payable returns (uint) { | |
balances[msg.sender] += msg.value; | |
LogDepositMade(msg.sender, msg.value); | |
return balances[msg.sender]; | |
} | |
/// @notice Withdraw ether from bank | |
/// @dev This does not return any excess ether sent to it | |
/// @param withdrawAmount amount you want to withdraw | |
/// @return The balance remaining for the user | |
function withdraw(uint withdrawAmount) public returns (uint remainingBal) { | |
if (balances[msg.sender] >= withdrawAmount) { | |
balances[msg.sender] -= withdrawAmount; | |
if (!msg.sender.send(withdrawAmount)) { | |
balances[msg.sender] += withdrawAmount; | |
} | |
} | |
return balances[msg.sender]; | |
} | |
/// @notice Get balance | |
/// @return The balance of the user | |
function balance() public constant returns (uint) { | |
return balances[msg.sender]; | |
} | |
function () public { | |
throw; | |
} | |
} |
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; | |
contract SimpleStorage { | |
uint storedData; | |
function set(uint x) public { | |
storedData = x; | |
} | |
function get() public constant returns (uint) { | |
return storedData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment