Skip to content

Instantly share code, notes, and snippets.

@nichanank
Created June 13, 2018 16:16
Show Gist options
  • Save nichanank/7a6d54980403499f5694af126e073101 to your computer and use it in GitHub Desktop.
Save nichanank/7a6d54980403499f5694af126e073101 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 Dog {
string output = "I'm a dog.";
uint posNumber = 2;
bool isDog = true;
int number = 1;
//"view" promises not to modify the contract state, it's a getter - won't consume any ether
function bark() view returns (string) {
return output;
}
function setOutput(string _output) {
output = _output;
}
}
pragma solidity ^0.4.0;
contract PersonContract {
struct Person {
string name;
uint age;
}
Person[] people;
function addPerson(string _name, uint _age) {
people.push(Person(_name, _age));
}
function getAverageAge(uint _id) view returns (uint) {
uint totalAge = 0;
for (uint i=0;i<people.length;i++) {
totalAge += people[i].age;
}
return totalAge / people.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment