Skip to content

Instantly share code, notes, and snippets.

@rBurgett
Last active June 29, 2019 16:51
Show Gist options
  • Save rBurgett/0624d19e7acf114202e75126aef1ce5c to your computer and use it in GitHub Desktop.
Save rBurgett/0624d19e7acf114202e75126aef1ce5c to your computer and use it in GitHub Desktop.
Ethereum Smart Contract example written in Solidity
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