Skip to content

Commit 8e54f2b

Browse files
authored
feat: Update to hardhat v3 with latest changes (#139)
* chore: Refactor project structure, migrate to `defineConfig`, update dependencies and enhance task setup * chore: Replace `setAction` with `setInlineAction` in task definitions * chore: Add `@types/mocha` to dev dependencies * chore: Add `hardhat-verify` plugin, update config and scripts * docs: Replace `hh` shorthand references with `npx hardhat` in README * docs: Update README to include Hardhat Keystore usage for managing secrets * ci: Specify Node.js version 24 in GitHub Actions setup * docs: Remove redundant whitespace in README command example
1 parent 8bf5f7f commit 8e54f2b

30 files changed

Lines changed: 4221 additions & 13614 deletions

.github/actions/setup/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ runs:
66
steps:
77
- name: Setup Node.js
88
uses: actions/setup-node@v4
9+
with:
10+
node-version: 24
911

1012
- name: Install
1113
run: npm install

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ coverage
44
coverage.json
55
typechain
66
typechain-types
7+
types
78

89
# Hardhat files
910
cache

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ node_modules
44
.env
55
.idea
66
typechain-types
7+
types
78
coverage

.solhint.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"extends": "solhint:recommended",
33
"plugins": [],
44
"rules": {
5-
"func-visibility": ["error", { "ignoreConstructors": true }]
5+
"func-visibility": ["error", { "ignoreConstructors": true }],
6+
"use-natspec": "off",
7+
"gas-calldata-parameters": "off",
8+
"gas-increment-by-one": "off"
69
}
710
}

README.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,13 @@ https://hardhat.org/getting-started/
6868

6969
Feel free to add more networks in `hardhat.config.ts` file.
7070

71-
## Hardhat Shorthand
71+
## Common Hardhat Commands
7272

73-
We recommend installing `hh autocomplete` so you can use `hh` shorthand globally.
74-
75-
```shell
76-
npm i -g hardhat-shorthand
77-
```
78-
79-
https://hardhat.org/guides/shorthand.html
80-
81-
### Common Shorthand Commands
82-
83-
- `hh compile` - to compile smart contract and generate typechain ts bindings
84-
- `hh test` - to run tests
85-
- `hh igntion` - to deploy smart contracts
86-
- `hh node` - to run a localhost node
87-
- `hh help` - to see all available commands
88-
- `hh TABTAB` - to use autocomplete
73+
- `npx hardhat compile` - to compile smart contract and generate typechain ts bindings
74+
- `npx hardhat test` - to run tests
75+
- `npx hardhat ignition` - to deploy smart contracts
76+
- `npx hardhat node` - to run a localhost node
77+
- `npx hardhat help` - to see all available commands
8978

9079
## Usage
9180

@@ -105,11 +94,32 @@ npm run compile
10594

10695
#### 3. Environment Setup
10796

108-
Create `.env` file and add your environment variables. You can use `.env.example` as a template.
97+
This project uses [Hardhat Keystore](https://hardhat.org/plugins/nomicfoundation-hardhat-keystore) to securely manage sensitive configuration variables like private keys and RPC URLs. Secrets are stored encrypted and never committed to disk in plain text.
98+
99+
**Set your private key**
100+
101+
```shell
102+
npx hardhat keystore set PRIVATE_KEY
103+
```
104+
105+
**Set your RPC URLs** (for the networks you plan to use)
106+
107+
```shell
108+
npx hardhat keystore set SEPOLIA_RPC_URL
109+
npx hardhat keystore set MAINNET_RPC_URL
110+
```
111+
112+
**Set your Etherscan API key** (for contract verification)
109113

110-
If you are going to use public network, make sure you include the right RPC provider for that network.
114+
```shell
115+
npx hardhat keystore set ETHERSCAN_API_KEY
116+
```
117+
118+
**List stored variables**
111119

112-
Make sure you include either `MNEMONIC` or `PRIVATE_KEY` in your `.env` file.
120+
```shell
121+
npx hardhat keystore list
122+
```
113123

114124
### Example Flow - Deploy ERC721 Token
115125

@@ -118,34 +128,34 @@ Make sure you include either `MNEMONIC` or `PRIVATE_KEY` in your `.env` file.
118128
#### 1.1 Deploy BasicERC721 Contract
119129

120130
```shell
121-
hh ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia
131+
npx hardhat ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia
122132
```
123133

124134
**Verify contract**
125135

126136
```shell
127-
hh ignition verify chain-11155111
137+
npx hardhat ignition verify chain-11155111 --network sepolia
128138
```
129139

130140
#### 1.2 Deploy and Verify
131141

132142
```shell
133-
hh ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify
143+
npx hardhat ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify
134144
```
135145

136146
#### 1.3 Deploy and Verify with Custom Parameters
137147

138148
Look at `ignition/parameters/custom.json` to see how to adjust contract parameters
139149

140150
```shell
141-
hh ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify --parameters ignition/parameters/custom.json
151+
npx hardhat ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify --parameters ignition/parameters/custom.json
142152
```
143153

144154
#### 2. Interact With Contract - Mint
145155

146156
```shell
147-
hh erc721-mint \
148-
--contract 0x1FEB5675Be6F256c4680BE447D6C353E02e04fb9 \
157+
npx hardhat erc721-mint \
158+
--contract 0x3fCB912bfb67B78121C5F326C24fBb0D2ca146dD \
149159
--recipient 0x73faDd7E476a9Bc2dA6D1512A528366A3E50c3cF \
150160
--network sepolia
151161
```

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default defineConfig([
2323
"**/artifacts",
2424
"**/cache",
2525
"**/typechain-types",
26+
"**/types",
2627
]),
2728
{
2829
extends: compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"),

hardhat.config.ts

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,59 @@
1-
import "@nomicfoundation/hardhat-toolbox"
1+
import { defineConfig, configVariable } from "hardhat/config"
2+
import hardhatToolboxMochaEthers from "@nomicfoundation/hardhat-toolbox-mocha-ethers"
3+
import hardhatVerify from "@nomicfoundation/hardhat-verify"
24

3-
import { HardhatUserConfig } from "hardhat/config"
5+
import { erc20MintTask } from "./tasks/erc20/mint.js"
6+
import { erc721MintTask } from "./tasks/erc721/mint.js"
7+
import { erc721BaseUriTask } from "./tasks/erc721/base-uri.js"
8+
import { erc721ContractUriTask } from "./tasks/erc721/contract-uri.js"
9+
import { erc1155MintTask } from "./tasks/erc1155/mint.js"
10+
import { erc1155BaseUriTask } from "./tasks/erc1155/base-uri.js"
11+
import { erc1155ContractUriTask } from "./tasks/erc1155/contract-uri.js"
12+
import { accountsTask } from "./tasks/utils/accounts.js"
13+
import { balanceTask } from "./tasks/utils/balance.js"
14+
import { blockNumberTask } from "./tasks/utils/block-number.js"
15+
import { sendEthTask } from "./tasks/utils/send-eth.js"
416

5-
import "@nomiclabs/hardhat-solhint"
6-
import "solidity-coverage"
7-
8-
import "dotenv/config"
9-
10-
import "./tasks"
11-
12-
const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || "https://eth-mainnet.g.alchemy.com/v2/your-api-key"
13-
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL || "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
14-
const MATIC_RPC_URL = process.env.MATIC_RPC_URL || "https://polygon-mainnet.g.alchemy.com/v2/your-api-key"
15-
const MUMBAI_RPC_URL = process.env.MUMBAI_RPC_URL || "https://polygon-mumbai.g.alchemy.com/v2/v3/your-api-key"
16-
17-
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "api-key"
18-
const POLYGONSCAN_API_KEY = process.env.POLYGONSCAN_API_KEY || "api-key"
19-
20-
// Import MNEMONIC or single private key
21-
const MNEMONIC = process.env.MNEMONIC || "your mnemonic"
22-
const PRIVATE_KEY = process.env.PRIVATE_KEY
23-
24-
const config: HardhatUserConfig = {
25-
defaultNetwork: "hardhat",
17+
export default defineConfig({
18+
plugins: [hardhatToolboxMochaEthers, hardhatVerify],
19+
tasks: [
20+
erc20MintTask,
21+
erc721MintTask,
22+
erc721BaseUriTask,
23+
erc721ContractUriTask,
24+
erc1155MintTask,
25+
erc1155BaseUriTask,
26+
erc1155ContractUriTask,
27+
accountsTask,
28+
balanceTask,
29+
blockNumberTask,
30+
sendEthTask,
31+
],
2632
networks: {
2733
mainnet: {
28-
url: MAINNET_RPC_URL,
29-
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
30-
},
31-
hardhat: {
32-
// // If you want to do some forking, uncomment this
33-
// forking: {
34-
// url: MAINNET_RPC_URL
35-
// }
36-
},
37-
localhost: {
38-
url: "http://127.0.0.1:8545",
34+
type: "http",
35+
url: configVariable("MAINNET_RPC_URL"),
36+
accounts: [configVariable("PRIVATE_KEY")],
3937
},
4038
sepolia: {
41-
url: SEPOLIA_RPC_URL,
42-
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
39+
type: "http",
40+
url: configVariable("SEPOLIA_RPC_URL"),
41+
accounts: [configVariable("PRIVATE_KEY")],
4342
},
44-
matic: {
45-
url: MATIC_RPC_URL,
46-
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
43+
polygon: {
44+
type: "http",
45+
url: configVariable("POLYGON_RPC_URL"),
46+
accounts: [configVariable("PRIVATE_KEY")],
4747
},
48-
mumbai: {
49-
url: MUMBAI_RPC_URL,
50-
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
48+
amoy: {
49+
type: "http",
50+
url: configVariable("AMOY_RPC_URL"),
51+
accounts: [configVariable("PRIVATE_KEY")],
5152
},
5253
},
53-
etherscan: {
54-
// Your API key for Etherscan
55-
// Obtain one at https://etherscan.io/
56-
apiKey: {
57-
mainnet: ETHERSCAN_API_KEY,
58-
sepolia: ETHERSCAN_API_KEY,
59-
// Polygon
60-
polygon: POLYGONSCAN_API_KEY,
61-
polygonMumbai: POLYGONSCAN_API_KEY,
54+
verify: {
55+
etherscan: {
56+
apiKey: configVariable("ETHERSCAN_API_KEY"),
6257
},
6358
},
6459
solidity: {
@@ -68,6 +63,4 @@ const config: HardhatUserConfig = {
6863
},
6964
],
7065
},
71-
}
72-
73-
export default config
66+
})

0 commit comments

Comments
 (0)