Last active
June 29, 2019 16:51
-
-
Save rBurgett/0624d19e7acf114202e75126aef1ce5c to your computer and use it in GitHub Desktop.
Ethereum Smart Contract example written in Solidity
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
contract MyContract { | |
// Declare persistent variables | |
uint256 public peopleCount = 0; | |
address owner; | |
mapping(uint => Person) public people; | |
modifier onlyByOwner() { | |
require(msg.sender == owner); | |
return "_"; | |
} | |
struct Person { | |
uint _id; | |
string _firstName; | |
string _lastName; | |
} | |
// Each Smart Contract is a singleton, so once deployed the constructor runs only once. | |
constructor() { | |
address = msg.sender; | |
} | |
// Public function which can be called on the Ethereum Virtual Machine | |
function addPerson(string memory _firstName, string memory _lastName) public onlyByOwner { | |
peopleCount += 1; | |
people[peopleCount] = Person(peopleCount, _firstName, _lastName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment