You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: develop/smart-contracts/dev-environments/hardhat.md
+27-89Lines changed: 27 additions & 89 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,10 +50,10 @@ Before getting started, ensure you have:
50
50
npm init -y
51
51
```
52
52
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:
@@ -62,7 +62,7 @@ Before getting started, ensure you have:
62
62
npx hardhat-polkadot init
63
63
```
64
64
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:
66
66
67
67
- **`contracts`**: Where your Solidity smart contracts live.
68
68
- **`test`**: Contains your test files that validate contract functionality.
@@ -85,61 +85,36 @@ Before getting started, ensure you have:
85
85
86
86
## Compile Your Contract
87
87
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:
89
89
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:
92
91
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:
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.
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:
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
-
133
108
2. Compile the contract with Hardhat:
134
109
135
110
```bash
136
111
npx hardhat compile
137
112
```
138
113
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:
140
115
141
116
```bash
142
-
ls artifacts-pvm/contracts/*.sol/
117
+
ls artifacts/contracts/*.sol/
143
118
```
144
119
145
120
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:
148
123
149
124
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.
150
125
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:
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:
170
127
171
128
```bash
172
129
npx hardhat node
173
130
```
174
131
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`.
176
133
177
134
The output will be something like this:
178
135
@@ -184,7 +141,7 @@ When testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/net
184
141
185
142
To run your test:
186
143
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.
188
145
189
146
2. Execute the following command to run your tests:
190
147
@@ -196,17 +153,10 @@ To run your test:
196
153
197
154
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:
198
155
199
-
1. Update the Hardhat configuration file to add the local network as a target for local deployment:
0 commit comments