Skip to content

Instantly share code, notes, and snippets.

@Ducasse
Created August 28, 2018 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ducasse/1ef2f2508cfd392ea7df07d8c71ee5a3 to your computer and use it in GitHub Desktop.
Save Ducasse/1ef2f2508cfd392ea7df07d8c71ee5a3 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
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;
}
}
}
pragma solidity ^0.4.24;
contract MyWallet {
address private owner;
uint8 constant private version = 1;
constructor() public {
owner = msg.sender;
}
modifier onlyOnwer(){
require (owner == msg.sender, "only the owner can do something");
_;
}
modifier checkBalance(uint amount){
require (address(this).balance >= amount, "not enough amount");
_;
}
function give (address rec, uint amount) public onlyOnwer checkBalance(amount) {
rec.transfer(amount);
}
function balance () public view returns(uint) {
return address(this).balance;
}
function deposit() public payable{
}
}
{
"accounts": {
"account{0}": "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
},
"linkReferences": {},
"transactions": [
{
"timestamp": 1535459921722,
"record": {
"value": "0",
"parameters": [],
"abi": "0x99ff0d9125e1fc9531a11262e15aeb2c60509a078c4cc4c64cefdfb06ff68647",
"contractName": "SimpleContract",
"bytecode": "60806040526040805190810160405280600681526020017f73696d706c6500000000000000000000000000000000000000000000000000008152506001908051906020019061004f929190610062565b5034801561005c57600080fd5b50610107565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a357805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d05782518255916020019190600101906100b5565b5b5090506100de91906100e2565b5090565b61010491905b808211156101005760008160009055506001016100e8565b5090565b90565b60df806101156000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bc5de3014604e5780635b4b73a9146076575b600080fd5b348015605957600080fd5b50606060a0565b6040518082815260200191505060405180910390f35b348015608157600080fd5b50609e6004803603810190808035906020019092919050505060a9565b005b60008054905090565b80600081905550505600a165627a7a72305820fe70862718bb29efb91c7558cd7b1b4ab291d8f6520271f77df79f131a1ce90e0029",
"linkReferences": {},
"name": "",
"type": "constructor",
"from": "account{0}"
}
},
{
"timestamp": 1535459954204,
"record": {
"value": "0",
"parameters": [
"1510"
],
"to": "created{1535459921722}",
"abi": "0x99ff0d9125e1fc9531a11262e15aeb2c60509a078c4cc4c64cefdfb06ff68647",
"name": "setData",
"type": "function",
"from": "account{0}"
}
}
],
"abis": {
"0x99ff0d9125e1fc9531a11262e15aeb2c60509a078c4cc4c64cefdfb06ff68647": [
{
"constant": false,
"inputs": [
{
"name": "d",
"type": "uint256"
}
],
"name": "setData",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [],
"name": "getData",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
}
}
pragma solidity ^ 0.4.24;
/**
* @title
* @author stef
*/
contract SimpleContract {
uint data;
string name = "simple";
constructor() public {
/* no needed */
}
function setData(uint d) public{
/* public just to say that everbody can call me */
data = d;
}
function getData() public view returns (uint){
/* view does not cost gas */
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment