Created
June 14, 2023 06:56
-
-
Save AllanJunLi/2541bf15624ff0fb087de66bc3905a82 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.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
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.8.18; | |
contract SimpleStorage { | |
// Basic Types: boolean, unit, int, address, bytes | |
// bool hasFavoriteNumber = true; | |
// uint256 favoriteNumber = 88; | |
// string favoriteNumberInText = "eighty-eight"; | |
// int256 favoriteInt = -88; | |
// address myAddress = 0x687Ff6d6a2D149f6475b83BaEC087067b62BE9E8; | |
// bytes32 favoriteBytes32 = "cat"; | |
uint256 myFavoriteNumber; // 0 | |
// uint256[] listOfFavoriteNumbers; | |
struct Person { | |
uint256 favoriteNumber; | |
string name; | |
} | |
// Person public pat = Person({favoriteNumber: 7, name: "Pat"}); | |
Person[] public listOfPeople; // [] | |
mapping(string => uint256) public nameToFavoriteNumber; | |
function store(uint256 _favoriteNumber) public { | |
myFavoriteNumber = _favoriteNumber; | |
} | |
// view - means read state | |
function retrieve() public view returns(uint256) { | |
return myFavoriteNumber; | |
} | |
function addPerson(string memory _name, uint256 _favoriteNumber) public { | |
listOfPeople.push(Person(_favoriteNumber, _name)); | |
nameToFavoriteNumber[_name] = _favoriteNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment