Skip to content

Commit bbb1ce0

Browse files
update hardhat documentation for web0 hackathon
1 parent 9e55775 commit bbb1ce0

File tree

2 files changed

+38
-97
lines changed

2 files changed

+38
-97
lines changed

.snippets/code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,31 @@ require('@parity/hardhat-polkadot');
66
/** @type import('hardhat/config').HardhatUserConfig */
77
module.exports = {
88
solidity: '0.8.28',
9-
resolc: {
10-
compilerSource: 'npm',
11-
},
129
networks: {
1310
hardhat: {
14-
polkavm: true,
11+
polkadot: {
12+
target: 'evm',
13+
},
1514
nodeConfig: {
16-
nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE',
15+
nodeBinaryPath: './bin/dev-node',
1716
rpcPort: 8000,
1817
dev: true,
1918
},
2019
adapterConfig: {
21-
adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',
20+
adapterBinaryPath: './bin/eth-rpc',
2221
dev: true,
2322
},
2423
},
2524
localNode: {
26-
polkavm: true,
25+
polkadot: {
26+
target: 'evm',
27+
},
2728
url: `http://127.0.0.1:8545`,
2829
},
2930
polkadotHubTestnet: {
30-
polkavm: true,
31+
polkadot: {
32+
target: 'evm',
33+
},
3134
url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',
3235
accounts: [vars.get('PRIVATE_KEY')],
3336
},

develop/smart-contracts/dev-environments/hardhat.md

Lines changed: 27 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ Before getting started, ensure you have:
5050
npm init -y
5151
```
5252

53-
3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts to PolkaVM bytecode and to spawn a local node compatible with PolkaVM:
53+
3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts and to spawn a local node for testing:
5454

5555
```bash
56-
npm install --save-dev @parity/hardhat-polkadot@0.1.9
56+
npm install --save-dev @parity/hardhat-polkadot@0.2.0
5757
```
5858

5959
4. Create a Hardhat project:
@@ -62,7 +62,7 @@ Before getting started, ensure you have:
6262
npx hardhat-polkadot init
6363
```
6464

65-
Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders:
65+
Follow the project creation wizard. Your project will be created with three main folders:
6666

6767
- **`contracts`**: Where your Solidity smart contracts live.
6868
- **`test`**: Contains your test files that validate contract functionality.
@@ -85,61 +85,36 @@ Before getting started, ensure you have:
8585

8686
## Compile Your Contract
8787

88-
The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible. When compiling your contract, there are two ways to configure your compilation process:
88+
The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher. To compile your project, follow these instructions:
8989

90-
- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use.
91-
- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options.
90+
1. Make sure your Hardhat configuration file looks like the following. Note that it may differ slightly based on the language choice made during the `init` step of setting up Hardhat:
9291

93-
To compile your project, follow these instructions:
94-
95-
1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network:
92+
```javascript title="hardhat.config.js" hl_lines="5-7 19-21 25-27"
93+
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:7:'
94+
```
9695

97-
=== "npm Configuration"
96+
To obtain the `dev-node` and `eth-rpc` binaries required in `nodeConfig` and `adapterConfig` respectively, check this [release](https://github.com/paritytech/hardhat-polkadot/releases/tag/nodes-19071579107){target=\_blank} and download the binaries as per your development platform and update the paths in your Hardhat config.
9897

99-
```javascript title="hardhat.config.js" hl_lines="9-11 14"
100-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:14'
101-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:33:35'
98+
!!! note
99+
You might have to give executable permissions to the binaries:
100+
```bash
101+
chmod +x /path/to/your/binary
102102
```
103-
104-
=== "Binary Configuration"
105-
106-
```javascript title="hardhat.config.js" hl_lines="9-14 17"
107-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js:1:17'
108-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js:36:38'
103+
For mac environments, sometimes the binaries get quarantined. To remove this, run:
104+
```bash
105+
xattr -d com.apple.quarantine /path/to/your/binary
109106
```
110107

111-
For the binary configuration, replace `INSERT_PATH_TO_RESOLC_COMPILER` with the proper path to the binary. To obtain the binary, check the [releases](https://github.com/paritytech/revive/releases){target=\_blank} section of the `resolc` compiler, and download the latest version.
112-
113-
The default settings used can be found in the [`constants.ts`](https://github.com/paritytech/hardhat-polkadot/blob/v0.1.5/packages/hardhat-polkadot-resolc/src/constants.ts#L8-L23){target=\_blank} file of the `hardhat-polkadot` source code. You can change them according to your project needs. Generally, the recommended settings for optimized outputs are the following:
114-
115-
```javascript title="hardhat.config.js" hl_lines="4-10"
116-
resolc: {
117-
...
118-
settings: {
119-
optimizer: {
120-
enabled: true,
121-
parameters: 'z',
122-
fallbackOz: true,
123-
runs: 200,
124-
},
125-
standardJson: true,
126-
},
127-
...
128-
}
129-
```
130-
131-
You can check the [`ResolcConfig`](https://github.com/paritytech/hardhat-polkadot/blob/v0.1.5/packages/hardhat-polkadot-resolc/src/types.ts#L26){target=\_blank} for more information about compilation settings.
132-
133108
2. Compile the contract with Hardhat:
134109

135110
```bash
136111
npx hardhat compile
137112
```
138113

139-
3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory:
114+
3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory:
140115
141116
```bash
142-
ls artifacts-pvm/contracts/*.sol/
117+
ls artifacts/contracts/*.sol/
143118
```
144119
145120
You should see JSON files containing the contract ABI and bytecode of the contracts you compiled.
@@ -148,31 +123,13 @@ To compile your project, follow these instructions:
148123
149124
Hardhat allows you to spin up a local testing environment to test and validate your smart contract functionalities before deploying to live networks. The `hardhat-polkadot` plugin provides the possibility to spin up a local node with an ETH-RPC adapter for running local tests.
150125
151-
For complete isolation and control over the testing environment, you can configure Hardhat to work with a fresh local Substrate node. This approach is ideal when you want to test in a clean environment without any existing state or when you need specific node configurations.
152-
153-
Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path:
154-
155-
```javascript title="hardhat.config.js" hl_lines="12-20"
156-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4'
157-
158-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:6:7'
159-
...
160-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:12:24'
161-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:34:35'
162-
```
163-
164-
Replace `INSERT_PATH_TO_SUBSTRATE_NODE` and `INSERT_PATH_TO_ETH_RPC_ADAPTER` with the actual paths to your compiled binaries. The `dev: true` flag configures both the node and adapter for development mode. To obtain these binaries, check the [Installation](/develop/smart-contracts/local-development-node#install-the-substrate-node-and-eth-rpc-adapter){target=\_blank} section on the Local Development Node page.
165-
166-
!!! warning
167-
If you're using the default `hardhat.config.js` created by the `hardhat-polkadot` plugin, it includes a `forking` section pointing to the Polkadot Hub TestNet. When you run `npx hardhat node`, Hardhat will start a fork of that network. To use your local node instead, comment out the `forking` section; otherwise, `npx hardhat node` will continue to use the forked network even if a local node is defined in the configuration.
168-
169-
Once configured, start your chosen testing environment with:
126+
Once you have set up the binaries as per the [Compile Your Contract](#compile-your-contract) section, start your local testing node with:
170127
171128
```bash
172129
npx hardhat node
173130
```
174131
175-
This command will launch either the forked network or local node (depending on your configuration) along with the ETH-RPC adapter, providing you with a complete testing environment ready for contract deployment and interaction. By default, the Substrate node will be running on `localhost:8000` and the ETH-RPC adapter on `localhost:8545`.
132+
This command will launch a local node along with the ETH-RPC adapter, providing you with a complete testing environment ready for contract deployment and interaction. By default, the Substrate node will be running on `localhost:8000` and the ETH-RPC adapter on `localhost:8545`.
176133
177134
The output will be something like this:
178135
@@ -184,7 +141,7 @@ When testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/net
184141

185142
To run your test:
186143

187-
1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section.
144+
1. Update the `hardhat.config.js` file as per the [Compile Your Contract](#compile-your-contract) section.
188145

189146
2. Execute the following command to run your tests:
190147

@@ -196,17 +153,10 @@ To run your test:
196153

197154
Before deploying to a live network, you can deploy your contract to a local node using [Ignition](https://hardhat.org/ignition/docs/getting-started#overview){target=\_blank} modules:
198155

199-
1. Update the Hardhat configuration file to add the local network as a target for local deployment:
200-
201-
```javascript title="hardhat.config.js" hl_lines="13-16"
202-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4'
156+
1. Make sure that the local network is added as a target for in your Hardhat configuration file for local deployment:
203157

204-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:6:7'
205-
...
206-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:12:13'
207-
...
208-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:24:28'
209-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:33:35'
158+
```javascript title="hardhat.config.js"
159+
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:24:29'
210160
```
211161

212162
2. Start a local node:
@@ -246,22 +196,10 @@ After testing your contract locally, you can deploy it to a live network. This g
246196
npx hardhat vars get PRIVATE_KEY
247197
```
248198

249-
4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target:
250-
251-
```javascript title="hardhat.config.js" hl_lines="18-22"
252-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4'
253-
254-
const { vars } = require('hardhat/config');
199+
4. Make sure the Polkadot Hub TestNet is added as a target in your Hardhat configuration file:
255200

256-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:6:7'
257-
...
258-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:12:13'
259-
...
260-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:24:24'
261-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:25:25'
262-
...
263-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:28:33'
264-
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:33:35'
201+
```javascript title="hardhat.config.js"
202+
--8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:30:36'
265203
```
266204

267205
6. Deploy your contract using Ignition:

0 commit comments

Comments
 (0)