Skip to content

Instantly share code, notes, and snippets.

@marsrvr
Created December 25, 2019 02:00
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 marsrvr/59545c0b9bdd88fe2807ad21ff7e065e to your computer and use it in GitHub Desktop.
Save marsrvr/59545c0b9bdd88fe2807ad21ff7e065e to your computer and use it in GitHub Desktop.
Simple mapping demo in Solidity.
pragma solidity 0.5.12;
// Every user will be able to create their account data
// and then retrieve ONLY their record.
contract StructDemo{
// stack variables
struct Person{
string name;
string species;
uint age;
uint height;
}
mapping(address => Person) private people;
// functions
function createPerson(string memory name, string memory species, uint age, uint height) public{
// retrieve user's Ethereum address.
address creator = msg.sender;
// map input data to user address
people[creator] = Person(name, species, age, height);
}
function getPerson() public returns (string memory name, string memory species, uint age, uint height){
// retrieve user's Ethereum address.
address creator = msg.sender;
// Can't natively return a structure yet.
return(people[creator].name, people[creator].species, people[creator].age, people[creator].height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment