Skip to content

Commit

Permalink
Merge pull request #1054 from Alex992Y/main
Browse files Browse the repository at this point in the history
for Sepolia test
  • Loading branch information
0x-stan authored Mar 20, 2024
2 parents d53158d + 6b2ebd1 commit 2cc5d96
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 113 deletions.
4 changes: 4 additions & 0 deletions basic/06-ethersjs-waffle/README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Waffle 详细使用方法可以参考 [Waffle 官网](https://ethereum-waffle.re

```bash
yarn install

#node 版本 v20.11.0
```

- 2 编译合约
Expand All @@ -53,6 +55,8 @@ yarn test

```bash
node index.js

## index.js 第19行 let address = "xxxxxxx" 修改成自己地址
```
## 说明
在使用命yarn install命令,提示无法找到yarn命令时(比如在VMware上跑),可以尝试执行:
Expand Down
4 changes: 4 additions & 0 deletions basic/06-ethersjs-waffle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ You can refer to the offical website of Waffle width the detailed usage(https://

```bash
yarn install

#node version v20.11.0
```

- 2 compile contracts
Expand All @@ -52,6 +54,8 @@ yarn test

```bash
node index.js

## index.js Line 19:let address = "xxxxxxx" change account to self
```

## Note
Expand Down
4 changes: 2 additions & 2 deletions basic/06-ethersjs-waffle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const { ethers } = require("ethers");
require("dotenv").config();
const privateKey = process.env.PRIVATE_KEY;

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

const web3Provider = new ethers.providers.InfuraProvider(
"goerli",
"sepolia",
process.env.INFURA_ID
);

Expand Down
59 changes: 37 additions & 22 deletions basic/07-hardhat/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ Hardhat Runner 是与 Hardhat 交互的 CLI 命令,是一个可扩展的任务
## 项目结构和配置 hardhat

```sh
mkdir 07-hardhat // 创建项目文件夹
cd 07-hardhat // 移动到项目文件夹下
cd 07-hardhat // 移到Hardhat项目文件夹
npm install --save-dev hardhat // 安装hardhat
npx hardhat // 创建hardhat项目
```
Expand All @@ -42,17 +41,17 @@ npx hardhat // 创建hardhat项目
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
Welcome to Hardhat v2.9.0
👷 Welcome to Hardhat v2.21.0 👷‍
? What do you want to do? ...
> Create a basic sample project
Create an advanced sample project
Create an advanced sample project that uses TypeScript
? What do you want to do?
Create a JavaScript project
Create a TypeScript project
Create a TypeScript project (with Viem)
Create an empty hardhat.config.js
Quit
```
我们使用'Create a basic sample project'选项,创建一个基础项目,后面的两个选项直接敲回车选择默认值。
我们使用'Create a JavaScript project'选项,创建一个基础项目,后面的两个选项直接敲回车选择默认值。
### 项目结构
Expand All @@ -77,7 +76,7 @@ hardhat.config.js
```js
require('@nomiclabs/hardhat-waffle');
require('dotenv').config();
require('@nomicfoundation/hardhat-verify');
module.exports = {
networks: {
// hardhat 内置测试网络(选填)
Expand All @@ -87,10 +86,10 @@ module.exports = {
},
// 你可以在这里配置任意网络
// goerli 测试网络
goerli: {
sepolia: {
// 请将 INFURA_ID 替换成你自己的
// url: 'https://goerli.infura.io/v3/{INFURA_ID}',
url: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
// url: 'https://sepolia.infura.io/v3/{INFURA_ID}',
url: 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
// 填写测试账户的私钥,可填写多个
accounts: [process.env.PRIVATE_KEY, ...]
Expand Down Expand Up @@ -140,16 +139,20 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle 插件
1. 安装 nodejs (略)
```js
//Node 版本 v20.11.0
```
2. 安装项目依赖:
```sh
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers dotenv
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers @nomicfoundation/hardhat-verify ethers dotenv
```
或使用 yarn 安装(需要先安装 yarn 依赖)
```sh
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @types/mocha dotenv
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @nomicfoundation/hardhat-verify @types/mocha dotenv
```
3. 配置私钥和网络:
Expand All @@ -159,6 +162,7 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle 插件
```js
PRIVATE_KEY = xxxxxxxxxxxxxxxx; // 替换为你的私钥
INFURA_ID = yyyyyyyy; // 替换为infura节点
APIKEY=zzzzzz; //替换etherscan的apikey,下文有介绍
```
## usage
Expand All @@ -179,6 +183,7 @@ npx hardhat compile
```sh
npx hardhat test
#test网络使用本机网络,不需要指定 --network <network name>
```
也可以指定运行某个特定测试文件
Expand All @@ -197,25 +202,35 @@ npx hardhat run ./scripts/deploy.js
指定运行的网络,例如在 goerli 测试网部署合约(请确保钱包地址在 goerli 测试网有足够的 gas 才能成功部署)
```sh
npx hardhat run ./scripts/deploy.js --network goerli
npx hardhat run ./scripts/deploy.js --network sepolia
#请记住此处运行完之后返回的 “deploy address“,下面 verify 在sepolia网络验证时会用到
```
### verify
验证智能合约,这里以`goerli`举例。
验证智能合约,这里以`sepolia`举例。
`hardhat.config.js` 添加配置:
```js
 etherscan: {
   apiKey: "<etherscan的api key>",
   apiKey: "<etherscan的api key>",//用process.env.APIKEY 获取变量
 }
```
https://etherscan.io/myapikey 官网创建账号,登陆之后,My Account(自己创建的账号实际名称) -> API Keys 菜单中创建
确保 hardhat.config.js里配置
require("@nomicfoundation/hardhat-verify");
且已安装上述模块 npm install --save-dev @nomicfoundation/hardhat-verify
运行脚本:
```shell
npx hardhat verify --network goerli <合约地址>
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network sepolia <合约地址>
#arguments_SimpleToken.js 中的数据为 第207行运行deplo.js脚本时,构造SimpleToken合约时,设置的参数
```
### task
Expand Down Expand Up @@ -288,7 +303,7 @@ contract Greeter {
}
```
在运行测试文件时,可以看到打印出的日志:
在运行测试文件时(命令:npx hardhat test ./test/greeter.test.js),可以看到打印出的日志:
```sh
Changing greeting from 'Hello, world!' to 'hello Dapp-Learning!'
Expand Down Expand Up @@ -317,15 +332,15 @@ Changing greeting from 'Hello, world!' to 'hello Dapp-Learning!'
npx hardhat run scripts/deploy.js --network <network-name>
```
这里的 `network-name` 替换成你指定的网络名称,这里可以换成 `goerli`,对应配置文件中的网络名称。
这里的 `network-name` 替换成你指定的网络名称,这里可以换成 `sepolia`,对应配置文件中的网络名称。
4. 验证智能合约
```bash
npx hardhat verify --network goerli <network-name> <contract-address>
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network <network-name> <contract-address>
```
`network-name` :你指定的网络名称,这里可以换成 `goerli`,对应配置文件中的网络名称。
`network-name` :你指定的网络名称,这里可以换成 `sepolia`,对应配置文件中的网络名称。
`contract-address` :上一步部署的合约地址。
Expand Down
54 changes: 34 additions & 20 deletions basic/07-hardhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Before learning hardhat, you need to understand some Knowledge points as follows
## Project structure and configuration hardhat

```sh
mkdir 07-hardhat // create folder
cd 07-hardhat // move to folder
npm install --save-dev hardhat // install hardhat
npx hardhat // initialize hardhat
Expand All @@ -40,17 +39,17 @@ Finished in inputing `npx hardhat`, it will show in the terminal:
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
Welcome to Hardhat v2.9.0
👷 Welcome to Hardhat v2.21.0 👷‍
? What do you want to do? ...
> Create a basic sample project
Create an advanced sample project
Create an advanced sample project that uses TypeScript
? What do you want to do?
Create a JavaScript project
Create a TypeScript project
Create a TypeScript project (with Viem)
Create an empty hardhat.config.js
Quit
```
We select 'Create a basic sample project' options to initialize a basic project, click enter directly in the next 2 steps.
We select 'Create a JavaScript project' options to initialize a basic project, click enter directly in the next 2 steps.
### Project stucture
Expand Down Expand Up @@ -85,10 +84,10 @@ module.exports = {
},
// you could config arbitrary network
// goerli testing network
goerli: {
sepolia: {
// place INFURA_ID to yours
// url: 'https://goerli.infura.io/v3/{INFURA_ID}',
url: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
// url: 'https://sepolia.infura.io/v3/{INFURA_ID}',
url: 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID, //<---- 在.env文件中配置自己的INFURA_ID
// place multiple privateKeyX to yours
accounts: [process.env.PRIVATE_KEY, ...]
Expand Down Expand Up @@ -138,17 +137,17 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle plugin
### Install dependencies
1. install nodejs (ignore)
# Node version v20.11.0
2. install project dependencies:
```sh
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers dotenv
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomicfoundation/hardhat-verify @nomiclabs/hardhat-ethers ethers dotenv
```
or use yarn to intall (yarn installed firstly)
```sh
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @types/mocha dotenv
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @nomicfoundation/hardhat-verify @types/mocha dotenv
```
3. config private key and network:
Expand All @@ -158,6 +157,7 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle plugin
```js
PRIVATE_KEY = xxxxxxxxxxxxxxxx; // place your private key
INFURA_ID = yyyyyyyy; // place infura node
APIKEY=zzzzzz; //replace etherscan apikey,will introduce below
```
## Usage
Expand All @@ -178,6 +178,7 @@ Run the command, hardhat will compile all test files in directory of `tests`, th
```sh
npx hardhat test
#test network no need assign --network <network name>
```
you could also specify some test files to run it
Expand All @@ -197,7 +198,10 @@ npx hardhat run ./scripts/deploy.js
Run the specified network, such as the contract deployed on goerli test network(make sure that the wallet could pay the gas)
```sh
npx hardhat run ./scripts/deploy.js --network goerli
npx hardhat run ./scripts/deploy.js --network sepolia
#Please remember the "deploy address" returned after running here, which will be used by verify in Sepolia network verification below
```
### Verify
Expand All @@ -207,15 +211,25 @@ Verify the smart contract, here is an example of `goerli`.
Add the following configuration to `hardhat.config.js`:
```js
 etherscan: {
   apiKey: "<etherscan的api key>",
  etherscan: {
   apiKey: "<etherscan的api key>", //Use process.env.APIKEY Get Variables
 }
```
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
Ensure configuration in hardhat.config.js
Require ("@nomofoundation/hardhat-verify");
And the above module npm install --savedev @nomicfoundation/hardhat-verify has been installed
Run script:
```shell
npx hardhat verify --network goerli <your contract address>
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network sepolia <contract address>
##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
```
### Task
Expand Down Expand Up @@ -316,15 +330,15 @@ Changing greeting from 'Hello, world!' to 'hello Dapp-Learning!'
npx hardhat run scripts/deploy.js --network <network-name>
```
`network-name` should be replaced with your networks, `goerli` is a choice which exists in the config file.
`network-name` should be replaced with your networks, `sepolia` is a choice which exists in the config file.
4. Verify smart contract
```bash
npx hardhat verify --network goerli <network-name> <contract-address>
npx hardhat verify --contract "contracts/SimpleToken.sol:SimpleToken" --constructor-args ./arguments_SimpleToken.js --network <network-name> <contract-address>
```
`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.
`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.
`contract-address` : The address of the contract deployed in the previous step.
Expand Down
3 changes: 3 additions & 0 deletions basic/07-hardhat/arguments_Greeter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
"Hello, world",
];
6 changes: 6 additions & 0 deletions basic/07-hardhat/arguments_SimpleToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = [
'SimpleToken',
'SimpleToken',
18,
10000000000,
];
Loading

0 comments on commit 2cc5d96

Please sign in to comment.