-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplestorage.sol
More file actions
35 lines (26 loc) · 1.07 KB
/
simplestorage.sol
File metadata and controls
35 lines (26 loc) · 1.07 KB
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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18; //stating my preffered version
contract SimpleStorage {
uint256 favoriteNumber; // It's the same as saying = 0 because no value was given
// uint256 [] listOfFavoriteNumbers;
struct Person{
string name;
uint256 __favoriteNumber;
}
//dynamic array
Person[] public listOfFriends;
mapping(string => uint256) public nameToFavoriteNumber;
mapping(uint256 => string) public favoriteNoToName;
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber; // storing the favorite number from whenever store function is called
}
//view means you're just reading state, pure
function retrieve() public view returns (uint256){
return favoriteNumber;
}
function addPerson(string memory _name, uint256 __favoriteNumber) public{
listOfFriends.push(Person( _name, __favoriteNumber));
nameToFavoriteNumber[_name] = __favoriteNumber;
favoriteNoToName[__favoriteNumber] = _name;
}
}