-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleStorage.sol
More file actions
36 lines (28 loc) · 987 Bytes
/
SimpleStorage.sol
File metadata and controls
36 lines (28 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// EVM, Ethereum Virtual Machine
// Ethereum, Polygon, Arbitrum, Optimism, Zksync
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24; // solidity versions
contract SimpleStorage {
//favoriteNumber gets initialized to 0 if no value is giving
uint256 myFavoriteNumber; // 0
// uint256[] listofFavoriteNumbers;
struct Person {
uint256 favoriteNumber;
string name;
}
Person[] public listofPeople; // []
// chelsea -> 232
mapping(string => uint256) public nameToFavoriteNumber;
function store (uint256 _favoriteNumber) public {
myFavoriteNumber = _favoriteNumber;
}
// view, pure
function retrieve() public view returns(uint256){
return myFavoriteNumber;
}
// calldata, memory, storage
function addPerson(string memory _name, uint256 _favoriteNumber) public {
listofPeople.push( Person(_favoriteNumber, _name) );
nameToFavoriteNumber [_name] =_favoriteNumber;
}
}