Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(basic): update task with the hardhat ^2.22.2 #1072

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion basic/07-hardhat/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PRIVATE_KEY=xxxxxxxxxxxxxxxx
INFURA_ID=yyyyyyyy
INFURA_ID=yyyyyyyy
APIKEY=zzzzzz
21 changes: 4 additions & 17 deletions basic/07-hardhat/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ hardhat.config.js
```js
require('@nomiclabs/hardhat-waffle');
require('dotenv').config();
require('@nomicfoundation/hardhat-verify');
module.exports = {
networks: {
// hardhat 内置测试网络(选填)
Expand Down Expand Up @@ -123,36 +122,26 @@ module.exports = {

hardhat 内置了一个特殊的安全测试网络,其名称也叫 `hardhat`, 通常你不需要对他进行特殊配置。该网络会模拟真实区块链网络的运行机制,并为你生成好 10 个测试账户(和 truffle 类似)。

### 使用插件

Hardhat 的很多功能都来自于插件,而作为开发者,你可以自由选择想使用的插件。

例如常用的 waffle 插件,使得 hardhat 可以集成 waffle 框架,进行开发,测试,部署。

```js
// hardhat.config.js
require('@nomiclabs/hardhat-waffle'); // hardhat waffle 插件
...
```

### 安装依赖

1. 安装 nodejs (略)

```js
安装 node
//Node 版本 v20.11.0
```
```

2. 安装项目依赖:

```sh
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers @nomicfoundation/hardhat-verify ethers dotenv
npm install
```

或使用 yarn 安装(需要先安装 yarn 依赖)

```sh
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @nomicfoundation/hardhat-verify @types/mocha dotenv
yarn
```

3. 配置私钥和网络:
Expand Down Expand Up @@ -222,8 +211,6 @@ npx hardhat run ./scripts/deploy.js --network sepolia
https://etherscan.io/myapikey 官网创建账号,登陆之后,My Account(自己创建的账号实际名称) -> API Keys 菜单中创建

确保 hardhat.config.js里配置
require("@nomicfoundation/hardhat-verify");
且已安装上述模块 npm install --save-dev @nomicfoundation/hardhat-verify

运行脚本:

Expand Down
20 changes: 2 additions & 18 deletions basic/07-hardhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ module.exports = {

hardhat has a special, secure and build-in testing network, named `hardhat`, you don't need a special configuration for it. The network will follow the mechanism in real block chain network, and it will generate 10 test accounts for you (just like truffle).

### Using plugins

Plugins have many functions in Hardhat, you could choose arbitrary plugins as a developer

Waffle plugins could make hardhat Integrated with waffle framework

```js
// hardhat.config.js
require('@nomiclabs/hardhat-waffle'); // hardhat waffle plugin
...
```

### Install dependencies

Expand All @@ -141,13 +130,13 @@ require('@nomiclabs/hardhat-waffle'); // hardhat waffle plugin
2. install project dependencies:

```sh
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomicfoundation/hardhat-verify @nomiclabs/hardhat-ethers ethers dotenv
npm install
```

or use yarn to intall (yarn installed firstly)

```sh
yarn add -D hardhat-deploy-ethers ethers chai chai-ethers mocha @types/chai @nomicfoundation/hardhat-verify @types/mocha dotenv
yarn
```

3. config private key and network:
Expand Down Expand Up @@ -219,11 +208,6 @@ https://etherscan.io/myapikey Create an account on the official website. After l

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
Expand Down
9 changes: 1 addition & 8 deletions basic/07-hardhat/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require('@nomiclabs/hardhat-waffle');
require("@nomicfoundation/hardhat-toolbox");
require('dotenv').config();
require('@nomicfoundation/hardhat-verify');


// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
Expand All @@ -25,11 +23,6 @@ function mnemonic() {
module.exports = {
solidity: '0.8.20',
networks: {
hardhat: {
forking: {
url: 'https://mainnet.infura.io/v3/'+ process.env.INFURA_ID,
}
},
localhost: {
url: 'http://localhost:8545',
//gasPrice: 125000000000, // you can adjust gasPrice locally to see how much it will cost on production
Expand Down
23 changes: 6 additions & 17 deletions basic/07-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "npx hardhat test"
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@types/chai": "^4.3.3",
"@types/mocha": "^10.0.0",
"chai": "^4.3.6",
"chai-ethers": "^0.0.1",
"dotenv": "^16.0.3",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.7.1",
"hardhat": "^2.9.0",
"hardhat-deploy-ethers": "^0.3.0-beta.13",
"mocha": "^10.0.0",
"sol-merger": "^3.1.0"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why delete the @OpenZeppelin

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use it in this task

"dotenv": "^16.4.5",
"hardhat": "^2.22.2"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^5.0.0"
}
}
14 changes: 3 additions & 11 deletions basic/07-hardhat/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@ async function main() {

console.log('Deploying contracts with the account:', deployer.address);

console.log('Account balance:', (await deployer.getBalance()).toString());
console.log('Account balance:', (await ethers.provider.getBalance(deployer.address)).toString());

const Token = await ethers.getContractFactory('SimpleToken');
const token = await Token.deploy('SimpleToken', 'SimpleToken', 18, 10000000000);
await token.waitForDeployment()

/** ---- for Greeter verify
const Greeter = await ethers.getContractFactory("Greeter");
const token = await Greeter.deploy("Hello, world");
await token.deployed();
*/


//--- for Greeter & SimpleToken both need, not delete

console.log('deploy address:', token.address);
console.log('deploy address:', token.target);


}
Expand Down
2 changes: 1 addition & 1 deletion basic/07-hardhat/test/erc20-all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("Token contract", function () {

// Check balances.
const finalOwnerBalance = await hardhatToken.balanceOf(owner.address);
expect(finalOwnerBalance).to.equal(initialOwnerBalance - 150);
expect(BigInt(finalOwnerBalance)).to.equal(BigInt(initialOwnerBalance) - BigInt(150));

const addr1Balance = await hardhatToken.balanceOf(addr1.address);
expect(addr1Balance).to.equal(100);
Expand Down
1 change: 0 additions & 1 deletion basic/07-hardhat/test/greeter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ describe("Greeter", function() {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");

await greeter.deployed();
expect(await greeter.greet()).to.equal("Hello, world!");

await greeter.setGreeting("hello Dapp-Learning!");
Expand Down
2 changes: 1 addition & 1 deletion basic/08-hardhat-graph/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TheGraph 中定义如何为数据建立索引,称为 Subgraph,它包含三
1. 安装相关依赖

```bash
yarn install
npm install

#node版本 v20.11.0
```
Expand Down
2 changes: 1 addition & 1 deletion basic/08-hardhat-graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TheGraph defines that how to create data index, which is called Subgraph, includ
1. Install related dependencies

```bash
yarn install
npm install

#node version v20.11.0
```
Expand Down
15 changes: 2 additions & 13 deletions basic/08-hardhat-graph/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require('@nomiclabs/hardhat-waffle');
const fs = require('fs');
require("@nomicfoundation/hardhat-toolbox");
require('dotenv').config();


Expand Down Expand Up @@ -43,14 +42,4 @@ module.exports = {
// Doesn't need an API key
enabled: true
}
};

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task('accounts', 'Prints the list of accounts', async () => {
const accounts = await ethers.getSigners();

for (const account of accounts) {
console.log(account.address);
}
});
};
22 changes: 6 additions & 16 deletions basic/08-hardhat-graph/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
{
"name": "08-hardhat-graph",
"version": "1.0.0",
"description": "[中文](./README-CN.md) / English",
"main": "hardhat.config.js",
"directories": {
"test": "test"
},
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@nomicfoundation/hardhat-verify": "^2.0.4",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"dependencies": {
"@openzeppelin/contracts": "^4.9.6",
"chai": "^5.1.0",
"dotenv": "^16.4.5",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.7.2",
"hardhat": "^2.21.0"
"hardhat": "^2.22.2"
},
"dependencies": {
"dotenv": "^16.4.5",
"@openzeppelin/contracts": "^4.4.2"
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^5.0.0"
}
}
5 changes: 3 additions & 2 deletions basic/08-hardhat-graph/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ async function main() {

console.log('Deploying contracts with the account:', deployer.address);

console.log('Account balance:', (await deployer.getBalance()).toString());
console.log('Account balance:', (await ethers.provider.getBalance(deployer.address)).toString());

const Token = await ethers.getContractFactory('SimpleToken');
const token = await Token.deploy('HHToken', 'HHT', 1, 100000000);


console.log('Contract address:', token.address);
console.log('Contract address:', token.target);

const receiver = '0x35D4A3Bd19382e5180824823E90312Be405c3707';
console.log('Transfer 50 to receiver ', receiver);
Expand Down
2 changes: 1 addition & 1 deletion basic/09-hardhat-react/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Dapp 开发中很重要的部分便是前端展示,本样例代码使用 hardh
2. 部署合约

```sh
npx hardhat run scripts/deploy.js --network goerli
npx hardhat run scripts/deploy.js --network sepolia
```

3. 启动 react
Expand Down
2 changes: 1 addition & 1 deletion basic/09-hardhat-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Put your private key in .env for easy access, formatted with "PRIVATE_KEY=xxxx".
2. Deploy contracts

```sh
npx hardhat run scripts/deploy.js --network goerli
npx hardhat run scripts/deploy.js --network sepolia
```

3. Startup react
Expand Down
7 changes: 2 additions & 5 deletions basic/09-hardhat-react/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
require('@nomiclabs/hardhat-waffle');

// The next line is part of the sample project, you don't need it in your
// project. It imports a Hardhat task definition, that can be used for
// testing the frontend.
require("@nomicfoundation/hardhat-toolbox");
require('./tasks/faucet');
const fs = require('fs');
require('dotenv').config();
Expand All @@ -11,6 +7,7 @@ function mnemonic() {
return process.env.PRIVATE_KEY;
}

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: '0.8.0',
networks: {
Expand Down
44 changes: 13 additions & 31 deletions basic/09-hardhat-react/package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
{
"name": "hardhat-hackathon-boilerplate",
"name": "09-hardhat-react",
"version": "1.0.0",
"description": "A boilerplate repository to get you started with Hardhat and Ethereum development",
"directories": {
"test": "test"
},
"description": "",
"main": "index.js",
"scripts": {
"test": "npx hardhat test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nomiclabs/hardhat-hackathon-boilerplate.git"
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"hardhat",
"ethereum",
"hackathon"
],
"author": "Nomic Labs",
"license": "MIT",
"bugs": {
"url": "https://github.com/nomiclabs/hardhat-hackathon-boilerplate/issues"
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@openzeppelin/contracts": "^4.1.0",
"dotenv": "^16.4.5",
"hardhat": "^2.22.2",
"ipfs-api": "^26.1.2"
},
"homepage": "https://github.com/nomiclabs/hardhat-hackathon-boilerplate#readme",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"chai": "^4.2.0",
"ethereum-waffle": "^3.1.1",
"ethers": "^5.0.0",
"hardhat": "^2.0.4",
"husky": "^4.2.5"
},
"dependencies": {
"@openzeppelin/contracts": "^4.4.2",
"dotenv": "^10.0.0"
"@nomicfoundation/hardhat-toolbox": "^5.0.0"
}
}
Loading
Loading