Created
June 10, 2022 13:42
-
-
Save agnel/371b94f933c5e75419c765c35a677117 to your computer and use it in GitHub Desktop.
The SimpleStorage contract in Solidity from Lesson 1: Welcome to Remix! Simple Storage on FreeCodeCamp
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
// SPDX-License-Identifier: MIT | |
pragma solidity >= 0.6.0 <0.9.0; | |
contract SimpleStorage { | |
// this will get initialized as 0 | |
uint256 favoriteNumber; | |
struct People { | |
uint256 favoriteNumber; | |
string name; | |
} | |
People[] public people; | |
mapping(string => uint256) public nameToFavoriteNumber; | |
function store(uint256 _favoriteNumber) public { | |
favoriteNumber = _favoriteNumber; | |
} | |
function retrieve() public view returns(uint256) { | |
return favoriteNumber; | |
} | |
function addPerson(string memory _name, uint256 _favoriteNumber) public { | |
people.push(People(_favoriteNumber, _name)); | |
nameToFavoriteNumber[_name] = _favoriteNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment