Skip to content

Commit a51a2cd

Browse files
committed
update hardhat
1 parent 1d0a061 commit a51a2cd

File tree

12 files changed

+232
-330
lines changed

12 files changed

+232
-330
lines changed

.ai/categories/smart-contracts.md

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10407,8 +10407,7 @@ Hardhat is a robust development environment for Ethereum-compatible chains that
1040710407

1040810408
Before getting started, ensure you have:
1040910409

10410-
- [Node.js](https://nodejs.org/){target=\_blank} (v16.0.0 or later) and npm installed.
10411-
- Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin.
10410+
- [Node.js](https://nodejs.org/){target=\_blank} (v22.5.0 or later) and npm installed.
1041210411
- Basic understanding of Solidity programming.
1041310412
- Some PAS test tokens to cover transaction fees (easily obtainable from the [Polkadot faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}). To learn how to get test tokens, check out the [Test Tokens](/develop/smart-contracts/connect-to-polkadot#test-tokens){target=\_blank} section.
1041410413

@@ -10430,7 +10429,7 @@ Before getting started, ensure you have:
1043010429
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:
1043110430

1043210431
```bash
10433-
npm install --save-dev @parity/hardhat-polkadot@0.1.9
10432+
npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6
1043410433
```
1043510434

1043610435
4. Create a Hardhat project:
@@ -10462,14 +10461,11 @@ Before getting started, ensure you have:
1046210461

1046310462
## Compile Your Contract
1046410463

10465-
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:
10466-
10467-
- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use.
10468-
- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options.
10464+
The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible.
1046910465

1047010466
To compile your project, follow these instructions:
1047110467

10472-
1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network:
10468+
1. Modify your Hardhat configuration file to specify which compilation process you will be using by specifying the `target` inside of the `polkadot` flag in the Hardhat network. By default it generates `pvm` bytecode, but you can use the EVM Backend by specifying `evm` as the `target`:
1047310469

1047410470
=== "npm Configuration"
1047510471

@@ -10482,12 +10478,12 @@ To compile your project, follow these instructions:
1048210478
/** @type import('hardhat/config').HardhatUserConfig */
1048310479
module.exports = {
1048410480
solidity: '0.8.28',
10485-
resolc: {
10486-
compilerSource: 'npm',
10487-
},
1048810481
networks: {
1048910482
hardhat: {
10490-
polkavm: true,
10483+
polkadot: {
10484+
target: 'evm'
10485+
},
10486+
nodeConfig: {
1049110487
},
1049210488
},
1049310489
};
@@ -10496,31 +10492,12 @@ To compile your project, follow these instructions:
1049610492
=== "Binary Configuration"
1049710493

1049810494
```javascript title="hardhat.config.js" hl_lines="9-14 17"
10499-
// hardhat.config.js
10500-
require('@nomicfoundation/hardhat-toolbox');
10501-
10502-
require('@parity/hardhat-polkadot');
10503-
10504-
/** @type import('hardhat/config').HardhatUserConfig */
10505-
module.exports = {
10506-
solidity: '0.8.28',
10507-
resolc: {
10508-
compilerSource: 'binary',
10509-
settings: {
10510-
compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER',
10511-
},
10512-
},
10513-
networks: {
10514-
hardhat: {
10515-
polkavm: true,
10516-
},
10517-
},
10518-
};
10495+
10496+
1051910497
```
1052010498

10521-
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.
1052210499

10523-
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:
10500+
The default settings used can be found in the [`constants.ts`](https://github.com/paritytech/hardhat-polkadot/blob/v0.2.0-pre6/packages/hardhat-polkadot-resolc/src/constants.ts#L15-L30){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:
1052410501

1052510502
```javascript title="hardhat.config.js" hl_lines="4-10"
1052610503
resolc: {
@@ -10532,35 +10509,34 @@ To compile your project, follow these instructions:
1053210509
fallbackOz: true,
1053310510
runs: 200,
1053410511
},
10535-
standardJson: true,
1053610512
},
1053710513
...
1053810514
}
1053910515
```
1054010516

10541-
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.
10517+
You can check the [`ResolcConfig`](https://github.com/paritytech/hardhat-polkadot/blob/v0.2.0-pre6/packages/hardhat-polkadot-resolc/src/types.ts#L26){target=\_blank} for more information about compilation settings.
1054210518

1054310519
2. Compile the contract with Hardhat:
1054410520

1054510521
```bash
1054610522
npx hardhat compile
1054710523
```
1054810524

10549-
3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory:
10525+
3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory:
1055010526

1055110527
```bash
10552-
ls artifacts-pvm/contracts/*.sol/
10528+
ls artifacts/contracts/*.sol/
1055310529
```
1055410530

1055510531
You should see JSON files containing the contract ABI and bytecode of the contracts you compiled.
1055610532

1055710533
## Set Up a Testing Environment
1055810534

10559-
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.
10535+
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 `anvil-polkadot` node for running local tests or fork a live chain using the ETH-RPC adapter.
1056010536

10561-
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.
10537+
For complete isolation and control over the testing environment, you can configure Hardhat to work with a fresh local `anvil-polkadot` node. This approach is ideal when you want to test in a clean environment without any existing state.
1056210538

10563-
Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path:
10539+
Configure a local node setup by adding the `anvil-polkadot` node binary path:
1056410540

1056510541
```javascript title="hardhat.config.js" hl_lines="12-20"
1056610542
// hardhat.config.js
@@ -10570,24 +10546,24 @@ require('@parity/hardhat-polkadot');
1057010546
/** @type import('hardhat/config').HardhatUserConfig */
1057110547
module.exports = {
1057210548
...
10573-
networks: {
10574-
hardhat: {
10575-
polkavm: true,
10549+
target: 'evm'
10550+
},
1057610551
nodeConfig: {
10577-
nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE',
10578-
rpcPort: 8000,
10579-
dev: true,
10552+
useAnvil: true,
10553+
nodeBinaryPath: 'INSERT_PATH_TO_ANVIL_NODE',
1058010554
},
1058110555
adapterConfig: {
1058210556
adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',
1058310557
dev: true,
1058410558
},
1058510559
},
10560+
localNode: {
10561+
polkadot: {
1058610562
},
1058710563
};
1058810564
```
1058910565

10590-
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.
10566+
Replace `INSERT_PATH_TO_ANVIL_NODE` with the actual path to your binary. To obtain this binary, 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.
1059110567

1059210568
!!! warning
1059310569
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.
@@ -10598,7 +10574,7 @@ Once configured, start your chosen testing environment with:
1059810574
npx hardhat node
1059910575
```
1060010576

10601-
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`.
10577+
This command will launch either the forked network along with the ETH-RPC adapter or the local `anvil-polkadot` node (depending on your configuration), providing you with a complete testing environment ready for contract deployment and interaction. By default, the `anvil-polkadot` node will be running on `localhost:8545`.
1060210578

1060310579
The output will be something like this:
1060410580

@@ -10651,12 +10627,12 @@ Before deploying to a live network, you can deploy your contract to a local node
1065110627
/** @type import('hardhat/config').HardhatUserConfig */
1065210628
module.exports = {
1065310629
...
10654-
networks: {
10655-
hardhat: {
10656-
...
10630+
target: 'evm'
1065710631
},
10658-
localNode: {
10659-
polkavm: true,
10632+
...
10633+
polkadot: {
10634+
target: 'evm'
10635+
},
1066010636
url: `http://127.0.0.1:8545`,
1066110637
},
1066210638
},
@@ -10713,15 +10689,15 @@ After testing your contract locally, you can deploy it to a live network. This g
1071310689
/** @type import('hardhat/config').HardhatUserConfig */
1071410690
module.exports = {
1071510691
...
10716-
networks: {
10717-
hardhat: {
10718-
...
10692+
target: 'evm'
1071910693
},
10720-
localNode: {
10694+
...
10695+
polkadot: {
10696+
target: 'evm'
1072110697
...
1072210698
},
1072310699
polkadotHubTestnet: {
10724-
polkavm: true,
10700+
polkadot: true,
1072510701
url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',
1072610702
accounts: [vars.get('PRIVATE_KEY')],
1072710703
},
@@ -10740,7 +10716,7 @@ After testing your contract locally, you can deploy it to a live network. This g
1074010716

1074110717
Once deployed, you can create a script to interact with your contract. To do so, create a file called `scripts/interact.js` and add some logic to interact with the contract.
1074210718

10743-
For example, for the default `MyToken.sol` contract, you can use the following file that connects to the contract at its address and retrieves the `unlockTime`, which represents when funds can be withdrawn. The script converts this timestamp into a readable date and logs it. It then checks the contract's balance and displays it. Finally, it attempts to call the withdrawal function on the contract, but it catches and logs the error message if the withdrawal is not yet allowed (e.g., before `unlockTime`).
10719+
For example, for the default `MyToken.sol` contract, you can use the following file that connects to the contract at its address and retrieves the token name and symbol. It then retrieves the `Total Supply`, which represents when funds can be withdrawn. Finally, it checks the deployer's balance and displays it.
1074410720

1074510721
```javascript title="interact.js"
1074610722
const hre = require('hardhat');
@@ -10797,7 +10773,7 @@ rm -rf node_modules package-lock.json
1079710773
After that, you can upgrade the plugin to the latest version by running the following commands:
1079810774

1079910775
```bash
10800-
npm install --save-dev @parity/hardhat-polkadot@latest
10776+
npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6
1080110777
npm install
1080210778
```
1080310779

0 commit comments

Comments
 (0)