Skip to content

Commit 6b2ebd1

Browse files
committed
for Sepolia test
1 parent d53158d commit 6b2ebd1

File tree

17 files changed

+181
-113
lines changed

17 files changed

+181
-113
lines changed

basic/06-ethersjs-waffle/README-cn.md

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Waffle 详细使用方法可以参考 [Waffle 官网](https://ethereum-waffle.re
2727

2828
```bash
2929
yarn install
30+
31+
#node 版本 v20.11.0
3032
```
3133

3234
- 2 编译合约
@@ -53,6 +55,8 @@ yarn test
5355

5456
```bash
5557
node index.js
58+
59+
## index.js 第19行 let address = "xxxxxxx" 修改成自己地址
5660
```
5761
## 说明
5862
在使用命yarn install命令,提示无法找到yarn命令时(比如在VMware上跑),可以尝试执行:

basic/06-ethersjs-waffle/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ You can refer to the offical website of Waffle width the detailed usage(https://
2626

2727
```bash
2828
yarn install
29+
30+
#node version v20.11.0
2931
```
3032

3133
- 2 compile contracts
@@ -52,6 +54,8 @@ yarn test
5254

5355
```bash
5456
node index.js
57+
58+
## index.js Line 19:let address = "xxxxxxx" change account to self
5559
```
5660

5761
## Note

basic/06-ethersjs-waffle/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const { ethers } = require("ethers");
66
require("dotenv").config();
77
const privateKey = process.env.PRIVATE_KEY;
88

9-
// const web3 = new Web3.providers.HttpProvider('https://kovan.infura.io/v3/0aae8358bfe04803b8e75bb4755eaf07');
9+
// const web3 = new Web3.providers.HttpProvider('https://sepolia.infura.io/v3/0aae8358bfe04803b8e75bb4755eaf07');
1010
// let web3Provider = new ethers.providers.Web3Provider(web3)
1111

1212
const web3Provider = new ethers.providers.InfuraProvider(
13-
"goerli",
13+
"sepolia",
1414
process.env.INFURA_ID
1515
);
1616

basic/07-hardhat/README-CN.md

+37-22
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Hardhat Runner 是与 Hardhat 交互的 CLI 命令,是一个可扩展的任务
2424
## 项目结构和配置 hardhat
2525

2626
```sh
27-
mkdir 07-hardhat // 创建项目文件夹
28-
cd 07-hardhat // 移动到项目文件夹下
27+
cd 07-hardhat // 移到Hardhat项目文件夹
2928
npm install --save-dev hardhat // 安装hardhat
3029
npx hardhat // 创建hardhat项目
3130
```
@@ -42,17 +41,17 @@ npx hardhat // 创建hardhat项目
4241
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
4342
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
4443
45-
Welcome to Hardhat v2.9.0
44+
👷 Welcome to Hardhat v2.21.0 👷‍
4645
47-
? What do you want to do? ...
48-
> Create a basic sample project
49-
Create an advanced sample project
50-
Create an advanced sample project that uses TypeScript
46+
? What do you want to do?
47+
Create a JavaScript project
48+
Create a TypeScript project
49+
Create a TypeScript project (with Viem)
5150
Create an empty hardhat.config.js
5251
Quit
5352
```
5453
55-
我们使用'Create a basic sample project'选项,创建一个基础项目,后面的两个选项直接敲回车选择默认值。
54+
我们使用'Create a JavaScript project'选项,创建一个基础项目,后面的两个选项直接敲回车选择默认值。
5655
5756
### 项目结构
5857
@@ -77,7 +76,7 @@ hardhat.config.js
7776
```js
7877
require('@nomiclabs/hardhat-waffle');
7978
require('dotenv').config();
80-
79+
require('@nomicfoundation/hardhat-verify');
8180
module.exports = {
8281
networks: {
8382
// hardhat 内置测试网络(选填)
@@ -87,10 +86,10 @@ module.exports = {
8786
},
8887
// 你可以在这里配置任意网络
8988
// goerli 测试网络
90-
goerli: {
89+
sepolia: {
9190
// 请将 INFURA_ID 替换成你自己的
92-
// url: 'https://goerli.infura.io/v3/{INFURA_ID}',
93-
url: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
91+
// url: 'https://sepolia.infura.io/v3/{INFURA_ID}',
92+
url: 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
9493
9594
// 填写测试账户的私钥,可填写多个
9695
accounts: [process.env.PRIVATE_KEY, ...]
@@ -140,16 +139,20 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle 插件
140139
141140
1. 安装 nodejs (略)
142141
142+
```js
143+
//Node 版本 v20.11.0
144+
```
145+
143146
2. 安装项目依赖:
144147
145148
```sh
146-
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers dotenv
149+
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers @nomicfoundation/hardhat-verify ethers dotenv
147150
```
148151
149152
或使用 yarn 安装(需要先安装 yarn 依赖)
150153
151154
```sh
152-
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @types/mocha dotenv
155+
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @nomicfoundation/hardhat-verify @types/mocha dotenv
153156
```
154157
155158
3. 配置私钥和网络:
@@ -159,6 +162,7 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle 插件
159162
```js
160163
PRIVATE_KEY = xxxxxxxxxxxxxxxx; // 替换为你的私钥
161164
INFURA_ID = yyyyyyyy; // 替换为infura节点
165+
APIKEY=zzzzzz; //替换etherscan的apikey,下文有介绍
162166
```
163167
164168
## usage
@@ -179,6 +183,7 @@ npx hardhat compile
179183
180184
```sh
181185
npx hardhat test
186+
#test网络使用本机网络,不需要指定 --network <network name>
182187
```
183188
184189
也可以指定运行某个特定测试文件
@@ -197,25 +202,35 @@ npx hardhat run ./scripts/deploy.js
197202
指定运行的网络,例如在 goerli 测试网部署合约(请确保钱包地址在 goerli 测试网有足够的 gas 才能成功部署)
198203
199204
```sh
200-
npx hardhat run ./scripts/deploy.js --network goerli
205+
npx hardhat run ./scripts/deploy.js --network sepolia
206+
207+
#请记住此处运行完之后返回的 “deploy address“,下面 verify 在sepolia网络验证时会用到
201208
```
202209
203210
### verify
204211
205-
验证智能合约,这里以`goerli`举例。
212+
验证智能合约,这里以`sepolia`举例。
206213
207214
`hardhat.config.js` 添加配置:
208215
209216
```js
210217
 etherscan: {
211-
   apiKey: "<etherscan的api key>",
218+
   apiKey: "<etherscan的api key>",//用process.env.APIKEY 获取变量
212219
 }
213220
```
214221
222+
https://etherscan.io/myapikey 官网创建账号,登陆之后,My Account(自己创建的账号实际名称) -> API Keys 菜单中创建
223+
224+
确保 hardhat.config.js里配置
225+
require("@nomicfoundation/hardhat-verify");
226+
且已安装上述模块 npm install --save-dev @nomicfoundation/hardhat-verify
227+
215228
运行脚本:
216229
217230
```shell
218-
npx hardhat verify --network goerli <合约地址>
231+
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network sepolia <合约地址>
232+
233+
#arguments_SimpleToken.js 中的数据为 第207行运行deplo.js脚本时,构造SimpleToken合约时,设置的参数
219234
```
220235
221236
### task
@@ -288,7 +303,7 @@ contract Greeter {
288303
}
289304
```
290305
291-
在运行测试文件时,可以看到打印出的日志:
306+
在运行测试文件时(命令:npx hardhat test ./test/greeter.test.js),可以看到打印出的日志:
292307
293308
```sh
294309
Changing greeting from 'Hello, world!' to 'hello Dapp-Learning!'
@@ -317,15 +332,15 @@ Changing greeting from 'Hello, world!' to 'hello Dapp-Learning!'
317332
npx hardhat run scripts/deploy.js --network <network-name>
318333
```
319334
320-
这里的 `network-name` 替换成你指定的网络名称,这里可以换成 `goerli`,对应配置文件中的网络名称。
335+
这里的 `network-name` 替换成你指定的网络名称,这里可以换成 `sepolia`,对应配置文件中的网络名称。
321336
322337
4. 验证智能合约
323338
324339
```bash
325-
npx hardhat verify --network goerli <network-name> <contract-address>
340+
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network <network-name> <contract-address>
326341
```
327342
328-
`network-name` :你指定的网络名称,这里可以换成 `goerli`,对应配置文件中的网络名称。
343+
`network-name` :你指定的网络名称,这里可以换成 `sepolia`,对应配置文件中的网络名称。
329344
330345
`contract-address` :上一步部署的合约地址。
331346

basic/07-hardhat/README.md

+34-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Before learning hardhat, you need to understand some Knowledge points as follows
2222
## Project structure and configuration hardhat
2323

2424
```sh
25-
mkdir 07-hardhat // create folder
2625
cd 07-hardhat // move to folder
2726
npm install --save-dev hardhat // install hardhat
2827
npx hardhat // initialize hardhat
@@ -40,17 +39,17 @@ Finished in inputing `npx hardhat`, it will show in the terminal:
4039
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
4140
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
4241
43-
Welcome to Hardhat v2.9.0
42+
👷 Welcome to Hardhat v2.21.0 👷‍
4443
45-
? What do you want to do? ...
46-
> Create a basic sample project
47-
Create an advanced sample project
48-
Create an advanced sample project that uses TypeScript
44+
? What do you want to do?
45+
Create a JavaScript project
46+
Create a TypeScript project
47+
Create a TypeScript project (with Viem)
4948
Create an empty hardhat.config.js
5049
Quit
5150
```
5251
53-
We select 'Create a basic sample project' options to initialize a basic project, click enter directly in the next 2 steps.
52+
We select 'Create a JavaScript project' options to initialize a basic project, click enter directly in the next 2 steps.
5453
5554
### Project stucture
5655
@@ -85,10 +84,10 @@ module.exports = {
8584
},
8685
// you could config arbitrary network
8786
// goerli testing network
88-
goerli: {
87+
sepolia: {
8988
// place INFURA_ID to yours
90-
// url: 'https://goerli.infura.io/v3/{INFURA_ID}',
91-
url: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
89+
// url: 'https://sepolia.infura.io/v3/{INFURA_ID}',
90+
url: 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
9291
9392
// place multiple privateKeyX to yours
9493
accounts: [process.env.PRIVATE_KEY, ...]
@@ -138,17 +137,17 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle plugin
138137
### Install dependencies
139138
140139
1. install nodejs (ignore)
141-
140+
# Node version v20.11.0
142141
2. install project dependencies:
143142
144143
```sh
145-
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers dotenv
144+
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomicfoundation/hardhat-verify @nomiclabs/hardhat-ethers ethers dotenv
146145
```
147146
148147
or use yarn to intall (yarn installed firstly)
149148
150149
```sh
151-
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @types/mocha dotenv
150+
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @nomicfoundation/hardhat-verify @types/mocha dotenv
152151
```
153152
154153
3. config private key and network:
@@ -158,6 +157,7 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle plugin
158157
```js
159158
PRIVATE_KEY = xxxxxxxxxxxxxxxx; // place your private key
160159
INFURA_ID = yyyyyyyy; // place infura node
160+
APIKEY=zzzzzz; //replace etherscan apikey,will introduce below
161161
```
162162
163163
## Usage
@@ -178,6 +178,7 @@ Run the command, hardhat will compile all test files in directory of `tests`, th
178178
179179
```sh
180180
npx hardhat test
181+
#test network no need assign --network <network name>
181182
```
182183
183184
you could also specify some test files to run it
@@ -197,7 +198,10 @@ npx hardhat run ./scripts/deploy.js
197198
Run the specified network, such as the contract deployed on goerli test network(make sure that the wallet could pay the gas)
198199
199200
```sh
200-
npx hardhat run ./scripts/deploy.js --network goerli
201+
npx hardhat run ./scripts/deploy.js --network sepolia
202+
203+
204+
#Please remember the "deploy address" returned after running here, which will be used by verify in Sepolia network verification below
201205
```
202206
203207
### Verify
@@ -207,15 +211,25 @@ Verify the smart contract, here is an example of `goerli`.
207211
Add the following configuration to `hardhat.config.js`:
208212
209213
```js
210-
 etherscan: {
211-
   apiKey: "<etherscan的api key>",
214+
  etherscan: {
215+
   apiKey: "<etherscan的api key>", //Use process.env.APIKEY Get Variables
212216
 }
213217
```
218+
https://etherscan.io/myapikey Create an account on the official website. After logging in, go to My Account (the actual name of the account you created) ->API Key
219+
220+
Ensure configuration in hardhat.config.js
221+
222+
Require ("@nomofoundation/hardhat-verify");
223+
224+
And the above module npm install --savedev @nomicfoundation/hardhat-verify has been installed
225+
214226
215227
Run script:
216228
217229
```shell
218-
npx hardhat verify --network goerli <your contract address>
230+
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network sepolia <contract address>
231+
232+
##The data in arguments SimpleToken.js are the parameters set during the construction of the SimpleToken contract when running the deploy. js script on line 207
219233
```
220234
221235
### Task
@@ -316,15 +330,15 @@ Changing greeting from 'Hello, world!' to 'hello Dapp-Learning!'
316330
npx hardhat run scripts/deploy.js --network <network-name>
317331
```
318332
319-
`network-name` should be replaced with your networks, `goerli` is a choice which exists in the config file.
333+
`network-name` should be replaced with your networks, `sepolia` is a choice which exists in the config file.
320334
321335
4. Verify smart contract
322336
323337
```bash
324-
npx hardhat verify --network goerli <network-name> <contract-address>
338+
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network <network-name> <contract-address>
325339
```
326340
327-
`network-name` : the name of the network you specify, here you can replace it with `goerli`, which corresponds to the network name in the configuration file.
341+
`network-name` : the name of the network you specify, here you can replace it with `sepolia`, which corresponds to the network name in the configuration file.
328342
329343
`contract-address` : The address of the contract deployed in the previous step.
330344

basic/07-hardhat/arguments_Greeter.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
"Hello, world",
3+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = [
2+
'SimpleToken',
3+
'SimpleToken',
4+
18,
5+
10000000000,
6+
];

0 commit comments

Comments
 (0)