Created
December 25, 2019 02:00
-
-
Save marsrvr/59545c0b9bdd88fe2807ad21ff7e065e to your computer and use it in GitHub Desktop.
Simple mapping demo 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
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