-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleStorage.sol
30 lines (28 loc) · 1.1 KB
/
SimpleStorage.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract SimpleStorage {
// Create a variable to hold favorite number
uint256 myNum ;
// Create a struct to hold favorite number and username
struct User {
uint256 myNum;
string username;
}
// Create an array to hold multiple structs
User[] private userArray;
// Create a mapping to get number by username
mapping (string => uint256) public usernameToMyNum;
// Create a function to receive a number and store it in 'myNum'
function addNumber(uint256 _myNum, string memory _username) public {
userArray.push(User({myNum: _myNum, username: _username}));
usernameToMyNum[_username] = _myNum;
}
// Create a function to modify the value of myNum. Note that this piece of code is to facilitate code structure in StorageFactory
function store(uint256 numToStore) public virtual {
myNum = numToStore;
}
// Create a function to retrieve the value of myNum
function get() public view returns (uint256){
return myNum;
}
}