-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleStorage.sol
51 lines (37 loc) · 1.81 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
contract SimpleStorage {
// Solidity basic data types: boolean, uint, int, address, bytes
bool hasFavoriteNumber = true;
uint256 favoriteNumber = 123; // uint16, uint32, uint64, uint128 can also be used, but it is a good practice to be explicit in Solidity
string favoriteNumberInText = "Five";
int256 num = -5;
address myAddress = 0x4D088Fe37422199dEAA6bc32FD7514b35C175908;
bytes32 favoriteBytes = 0x6361740000000000000000000000000000000000000000000000000000000000; // bytes can also be used, but it is good practice to be explicit in Solidity
uint256 favoriteNumberStored;
//mappings
mapping(string => uint256) public nameFavoriteNumber;
People public person = People(2 ,"Shubham");
struct People {
uint256 favoriteNumber;
string name;
}
People[] public people;
function store(uint256 _favoriteNumber) public {
favoriteNumberStored = _favoriteNumber;
}
// Calling View Function costs nothing but if we call it inside a function which need gas fees then the view functions also causes extra gas fees
// View, pure keywords allow and we do not need to spend any gas fees ;
function retrieve() public view returns(uint256){
return favoriteNumber;
}
function addPerson(string memory _name, uint256 _favoriteNumber) public {
People memory newPerson = People({favoriteNumber:_favoriteNumber,name:_name});
people.push(newPerson);
nameFavoriteNumber[_name] = _favoriteNumber;
}
// EVM
// Stack Memory Storage Calldata
//calldata, memory and storage
// Arrays, Strings , mappings and structs insolidity requires to be defined with either calldata or memory
}