Last active
November 24, 2019 16:03
-
-
Save owans/914c4eab371931549f0c0b9d4aa00c73 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.5.11+commit.c082d0b4.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.5.11; | |
contract HelloWorld{ | |
string public message; | |
function setMessage (string memory newMessage) public { | |
message = newMessage; | |
} | |
} |
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.5.11; | |
pragma experimental ABIEncoderV2; | |
contract Voter{ | |
uint[] public votes; | |
string[] public options; | |
mapping (address => bool) hasVoted; | |
constructor(string[] memory _options) public{ | |
options = _options; | |
votes.length = options.length; | |
} | |
function vote(uint option) public{ | |
require(0 <= option && option < options.length, 'Invalid Option'); | |
require(!hasVoted[msg.sender], 'Account has already voted'); | |
votes[option] = votes[option] + 1; | |
hasVoted[msg.sender] = true; | |
} | |
function getOptions() public view returns (string[] memory){ | |
return options; | |
} | |
function getVotes() public view returns (uint[] memory){ | |
return votes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment