-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequirment.txt
203 lines (140 loc) · 8.19 KB
/
Requirment.txt
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
Remix is an IDE : Integrated Development Environment
Need to read:
https://docs.soliditylang.org/en/v0.8.21/
https://docs.chain.link/data-feeds/using-data-feeds
https://solidity-by-example.org/library/
One of the most commen libraries that was ysed for a long time is SafeMath.sol:
https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/utils/math
for withdraw the money by transfer method :
https://solidity-by-example.org/sending-ether/
#note that unchecked key word makes your code a little bit more gas efficient
for custom errors :
https://soliditylang.org/blog/2021/04/21/custom-errors/
for receive and fallback:
https://docs.soliditylang.org/en/v0.8.13/contracts.html?#receive-ether-function
for check out the details of the transaction of our contract :
https://etherscan.io/address/0xf094D1fB5083c6c55f804954917AA5FFA6041906
here the github repo for asking questions:
https://github.com/Cyfrin/foundry-full-course-f23
here a other websites for asking questions:
https://peeranha.io/
https://web3education.dev/
*******************
the good format for asking questions"
describe what are you doing and what's the issue then
here is my error:
'''
type all part of error
'''
here is my code:
'''
name of the programming language which you are using
tpye your code
'''
********************
don't forget to check out the speedrun ethereum.com and see Austin Griffin's videos related to that
*************************************
now we are moving to Foundry , a proffesional smart contract framework, similar to hard hat(Javascript based) or brownie(python based).
foundry is solidity based.
it's famous because of its speed.
https://getfoundry.sh
In remix we do lot of stuff manually ( testing or deploying ,...)
if we change 10 function,in remix, we must test all 10 functions till we make sure that they are working or not.
for security and auditing, foundry is the most popular tool amongst Auditors
in frrecodecamp in YouTube, watch the Bash scripting tutorial for biginners
we must install solidity and better toml for better using of foundry in VSCode.
******************
use ctrl+p for opening search section in VSCode and type " > " then type setting and go to the open users settings and search for the format on save and check the box till when you save your code, it will automatically check and reform your code format.
******************
For compileing our code, we need to type " forge build or forge compile " in the vscode terminal.
after compiling, some new folders come up. the have the same information which remix has.
***********************
Now it's time to deploying to a local blockchain like " Anvil or Ganache "
Foundry comes built in with a virtual environment in the shell and by running anvil in terminal you will get an outputs.
Ganache eth chain : https://trufflesuite.com/ganache/
Ganache is a one click blockchainand it gives us a auser interface or an app for us to look at our transactions in an easier way.
It gives us a account address with a private key. don't use it on public blockchain.
for installing Ganache, after downloading it, type the following commands in terminal:
chmod a+x ganache-2.7.1-linux-x86_64.AppImage
sudo apt install fuse
./ganache-2.7.1-linux-x86_64.AppImage
now go into your metamask account and go to settings then into networks and create a new network like sepolia:
for RPC URL: if yoy're working with Ganache, there is a RPC server.in anvil there is a listening at the bottom.
for chain ID, in anvil it is 31337 and in Ganache it is 1337
currency symbol is going to be ETH
*******
copy private key from Ganache and vlivk on import account in metamask and then you will have there some currency.
*******
***********************
YOu need a connection to a node in order to send transactions.if yoou want to send transaction to your own node, you would run something like gath which is an execution
client and then something maybe like techu a prism whoch is a consesnus client and send transaction there.
^^^^try to run your own ethereum node. ^^^^
***********************
for deploying into a local clockchain, use forge --help in vscode terminal
use : forge create SimpleStorage --rpc-url http://127.0.0.1:7545 --interactive
then inter your private key
*** note that never use your real private key in vscode
now if you go in block section in Ganache you can see the new block
****************
Deploying to a local blockchain (Scripting)
## instead of doing the command line we're actually going to write a script for us to deploy our code.
for writing a script, for name of that we must use ".s.sol " after name of the program.
you can use : https://book.getfoundry.sh/tutorials/solidity-scripting
then you must write :
import "forge-std/Script.sol";
till the vscode knows that this is a script and start your code like:
contract DeploySimpleStorage is Script{}
************
any transaction taht we want to send we must put it between :
vm.startBroadcast();
vm.stopBroadcast();
*************
For deploying it:
forge script script/DeploySimpleStorage.s.sol
if we want to deploy in our chain:
forge script script/DeploySimpleStorage.s.sol --rpc-url http://YOUR RPC --broadcast --private-key
***********************************************
In Foundry, if you don't specify an RPC URL,it'll just automatically deploy your contract or run your script on a temporary Anvil chain.
**********************************************
after deploying you can go into broadcast file in foundry-f23/foundry-simple-storage-f23 and go into run-latest.json and check out the transactions details.
there is the hex value of the gas not amount of gas.
**********
you can use cast (it's bulit in foundray) to convert between hex and numbers.
the command: cast --to-base hex dec
**********
if our contract or function is payable, we can add value for it like:
SimpleStorage simpleStorage = new SimpleStorage{value:ether}();
there are rsv vakues allow our private key to sign the transaction.
your nonce increments every time you send transaction.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Patrick has a security course comming, don't forget watching it.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
we don't want to paste our private key in plain text so what else can we do????
We can put the private key and rpc url in the .env file and then put it in the gitignore .
thenn run the " source .env" to put everything inside of .env into the shell
after that we can use the following command:
forge script script/DeploySimpleStorage.s.sol --rpc-url $RPC_URL --broadcast --private-key $PRIVATE_KEY
there is a one more step to make this even more secure:
there is an issue in the founfry repo right now called improve wallet management UX using Keystore.
https://github.com/foundry-rs/foundry/issues/1869
if you run forge script --help : you can see a section where you can actually pass a path to a encrypted keystore file and a password.
Keystore is a file that has your private key but encrypted by a password.
make sure that you're going to read the following :
https://github.com/Cyfrin/foundry-full-course-f23/discussions/5
//////////////////////////////////////////////////////////////
other way to deploy our contract is the third web drploy
for this aim, use the follo=wing command in your vscode terminal:
npx thirdweb deploy ///// firstly, we must install node json from https://github.com/nodesource/distributions according to what version do we want to install.
************************************
now if we want to call a function from our contract:
cast send 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 "store(uint256)" 123 --rpc-url $RPC_URL --private-key $PRIVATE_KEY
** cast send is related to orange boxs ic the remix and cast call is related to blue boxs in the remix
cast call 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 "retrieve()" -> it gets the hex value back
if we use cast --to-base hex dec we can get the number which we give the store function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
test net Demo
https://www.alchemy.com/
we can sign up for a node as a service that we can actually send transactions to.
Alchemy is the only scalable,reliable and accurate blockchain infrastructure.
all logs are recorded as bytes 32 in foundry.