Skip to content

Commit 30f4fee

Browse files
committed
feat: new cn
1 parent 8a6ad34 commit 30f4fee

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

basic/07-hardhat/README-cn.md

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,36 @@ Hardhat Runner 是与 Hardhat 交互的 CLI 命令,是一个可扩展的任务
2424
## 项目结构和配置 hardhat
2525

2626
```sh
27+
mkdir 07-hardhat // 创建项目文件夹
28+
cd 07-hardhat // 移动到项目文件夹下
2729
npm install --save-dev hardhat // 安装hardhat
2830
npx hardhat // 创建hardhat项目
2931
```
3032

33+
输入`npx hardhat`后,命令行中会出现如下的界面:
34+
35+
```sh
36+
888 888 888 888 888
37+
888 888 888 888 888
38+
888 888 888 888 888
39+
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
40+
888 888 "88b 888P" d88" 888 888 "88b "88b 888
41+
888 888 .d888888 888 888 888 888 888 .d888888 888
42+
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
43+
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
44+
45+
Welcome to Hardhat v2.9.0
46+
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
51+
Create an empty hardhat.config.js
52+
Quit
53+
```
54+
55+
我们使用'Create a basic sample project'选项,创建一个基础项目,后面的两个选项直接敲回车选择默认值。
56+
3157
### 项目结构
3258
3359
一个标准的使用 hardhat 构建的项目通常是这样的:
@@ -49,6 +75,9 @@ hardhat.config.js
4975
`hardhat.config.js` 配置文件示例
5076
5177
```js
78+
require('@nomiclabs/hardhat-waffle');
79+
require('dotenv').config();
80+
5281
module.exports = {
5382
networks: {
5483
// hardhat 内置测试网络(选填)
@@ -60,9 +89,11 @@ module.exports = {
6089
// rinkeby 测试网络
6190
rinkeby: {
6291
// 请将 INFURA_ID 替换成你自己的
63-
url: 'https://rinkeby.infura.io/v3/{INFURA_ID}',
92+
// url: 'https://rinkeby.infura.io/v3/{INFURA_ID}',
93+
url: 'https://rinkeby.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
94+
6495
// 填写测试账户的私钥,可填写多个
65-
accounts: [privateKey1, privateKey2, ...]
96+
accounts: [process.env.PRIVATE_KEY, ...]
6697
}
6798
},
6899
solidity: {
@@ -112,30 +143,18 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle 插件
112143
2. 安装项目依赖:
113144
114145
```sh
115-
npm install
146+
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers dotenv
116147
```
117148
118149
或使用 yarn 安装(需要先安装 yarn 依赖)
119150
120151
```sh
121-
yarn
152+
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @types/mocha dotenv
122153
```
123154
124155
3. 配置私钥和网络:
125156
126-
windows:
127-
128-
```bash
129-
copy .env.example .env
130-
```
131-
132-
linux:
133-
134-
```bash
135-
cp .env.example .env
136-
```
137-
138-
`.env` 文件中填写私钥和 infura 节点
157+
在项目文件夹下新建`.env`文件,并且在 `.env` 文件中填写私钥和 infura 节点
139158
140159
```js
141160
PRIVATE_KEY = xxxxxxxxxxxxxxxx; // 替换为你的私钥
@@ -170,13 +189,27 @@ npx hardhat test ./test/Greeter.test.js
170189
171190
### run
172191
192+
拷贝 script 目录下的脚本,作为我们的运行脚本:
193+
194+
windows:
195+
196+
```bash
197+
copy .\scripts\sample-script.js .\scripts\deploy.js
198+
```
199+
200+
linux:
201+
202+
```bash
203+
cp ./scripts/sample-script.js ./scripts/deploy.js
204+
```
205+
173206
运行指定脚本。如果不指定运行网络,会默认在 hardhat 内置网络内运行 (Hardhat Network)。
174207
175208
```sh
176209
npx hardhat run ./scripts/deploy.js
177210
```
178211
179-
指定运行的网络,例如在 rinkeby 测试网部署合约
212+
指定运行的网络,例如在 rinkeby 测试网部署合约(请确保钱包地址在 rinkeby 测试网有足够的 gas 才能成功部署)
180213
181214
```sh
182215
npx hardhat run ./scripts/deploy.js --network rinkeby

0 commit comments

Comments
 (0)