diff --git a/.ai/categories/smart-contracts.md b/.ai/categories/smart-contracts.md index 8b967c0fb..11f1dce3b 100644 --- a/.ai/categories/smart-contracts.md +++ b/.ai/categories/smart-contracts.md @@ -10407,8 +10407,7 @@ Hardhat is a robust development environment for Ethereum-compatible chains that Before getting started, ensure you have: -- [Node.js](https://nodejs.org/){target=\_blank} (v16.0.0 or later) and npm installed. - - Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin. +- [Node.js](https://nodejs.org/){target=\_blank} (v22.5.0 or later) and npm installed. - Basic understanding of Solidity programming. - 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. @@ -10430,7 +10429,7 @@ Before getting started, ensure you have: 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: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 ``` 4. Create a Hardhat project: @@ -10462,65 +10461,13 @@ Before getting started, ensure you have: ## Compile Your Contract -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: - -- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use. -- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options. +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible. To compile your project, follow these instructions: -1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network: - - === "npm Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-11 14" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); - - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'npm', - }, - networks: { - hardhat: { - polkavm: true, - }, - }, - }; - ``` - - === "Binary Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-14 17" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); - - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'binary', - settings: { - compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER', - }, - }, - networks: { - hardhat: { - polkavm: true, - }, - }, - }; - ``` - - 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. +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`. - 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: + 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: ```javascript title="hardhat.config.js" hl_lines="4-10" resolc: { @@ -10532,13 +10479,12 @@ To compile your project, follow these instructions: fallbackOz: true, runs: 200, }, - standardJson: true, }, ... } ``` - 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. + 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. 2. Compile the contract with Hardhat: @@ -10546,21 +10492,21 @@ To compile your project, follow these instructions: npx hardhat compile ``` -3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory: +3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory: ```bash - ls artifacts-pvm/contracts/*.sol/ + ls artifacts/contracts/*.sol/ ``` You should see JSON files containing the contract ABI and bytecode of the contracts you compiled. ## Set Up a Testing Environment -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. +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. -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. +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. -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: +Configure a local node setup by adding the `anvil-polkadot` node binary path: ```javascript title="hardhat.config.js" hl_lines="12-20" // hardhat.config.js @@ -10570,24 +10516,24 @@ require('@parity/hardhat-polkadot'); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - polkavm: true, + target: 'evm' + }, nodeConfig: { - nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE', - rpcPort: 8000, - dev: true, + useAnvil: true, + nodeBinaryPath: 'INSERT_PATH_TO_ANVIL_NODE', }, adapterConfig: { adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER', dev: true, }, }, + localNode: { + polkadot: { }, }; ``` -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. +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. !!! warning 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 +10544,7 @@ Once configured, start your chosen testing environment with: npx hardhat node ``` -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`. +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`. The output will be something like this: @@ -10651,12 +10597,12 @@ Before deploying to a live network, you can deploy your contract to a local node /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - ... + target: 'evm' }, - localNode: { - polkavm: true, + ... + polkadot: { + target: 'evm' + }, url: `http://127.0.0.1:8545`, }, }, @@ -10713,15 +10659,15 @@ After testing your contract locally, you can deploy it to a live network. This g /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - ... + target: 'evm' }, - localNode: { + ... + polkadot: { + target: 'evm' ... }, polkadotHubTestnet: { - polkavm: true, + polkadot: true, url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', accounts: [vars.get('PRIVATE_KEY')], }, @@ -10740,7 +10686,7 @@ After testing your contract locally, you can deploy it to a live network. This g 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. -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`). +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. ```javascript title="interact.js" const hre = require('hardhat'); @@ -10797,7 +10743,7 @@ rm -rf node_modules package-lock.json After that, you can upgrade the plugin to the latest version by running the following commands: ```bash -npm install --save-dev @parity/hardhat-polkadot@latest +npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 npm install ``` diff --git a/.ai/categories/tooling.md b/.ai/categories/tooling.md index ea2a85a71..3d509a3d5 100644 --- a/.ai/categories/tooling.md +++ b/.ai/categories/tooling.md @@ -19821,8 +19821,7 @@ Hardhat is a robust development environment for Ethereum-compatible chains that Before getting started, ensure you have: -- [Node.js](https://nodejs.org/){target=\_blank} (v16.0.0 or later) and npm installed. - - Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin. +- [Node.js](https://nodejs.org/){target=\_blank} (v22.5.0 or later) and npm installed. - Basic understanding of Solidity programming. - 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. @@ -19844,7 +19843,7 @@ Before getting started, ensure you have: 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: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 ``` 4. Create a Hardhat project: @@ -19876,65 +19875,13 @@ Before getting started, ensure you have: ## Compile Your Contract -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: - -- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use. -- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options. +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible. To compile your project, follow these instructions: -1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network: - - === "npm Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-11 14" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); +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`. - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'npm', - }, - networks: { - hardhat: { - polkavm: true, - }, - }, - }; - ``` - - === "Binary Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-14 17" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); - - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'binary', - settings: { - compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER', - }, - }, - networks: { - hardhat: { - polkavm: true, - }, - }, - }; - ``` - - 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. - - 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: + 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: ```javascript title="hardhat.config.js" hl_lines="4-10" resolc: { @@ -19946,13 +19893,12 @@ To compile your project, follow these instructions: fallbackOz: true, runs: 200, }, - standardJson: true, }, ... } ``` - 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. + 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. 2. Compile the contract with Hardhat: @@ -19960,21 +19906,21 @@ To compile your project, follow these instructions: npx hardhat compile ``` -3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory: +3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory: ```bash - ls artifacts-pvm/contracts/*.sol/ + ls artifacts/contracts/*.sol/ ``` You should see JSON files containing the contract ABI and bytecode of the contracts you compiled. ## Set Up a Testing Environment -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. +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. -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. +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. -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: +Configure a local node setup by adding the `anvil-polkadot` node binary path: ```javascript title="hardhat.config.js" hl_lines="12-20" // hardhat.config.js @@ -19984,24 +19930,24 @@ require('@parity/hardhat-polkadot'); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - polkavm: true, + target: 'evm' + }, nodeConfig: { - nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE', - rpcPort: 8000, - dev: true, + useAnvil: true, + nodeBinaryPath: 'INSERT_PATH_TO_ANVIL_NODE', }, adapterConfig: { adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER', dev: true, }, }, + localNode: { + polkadot: { }, }; ``` -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. +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. !!! warning 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. @@ -20012,7 +19958,7 @@ Once configured, start your chosen testing environment with: npx hardhat node ``` -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`. +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`. The output will be something like this: @@ -20065,12 +20011,12 @@ Before deploying to a live network, you can deploy your contract to a local node /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - ... + target: 'evm' }, - localNode: { - polkavm: true, + ... + polkadot: { + target: 'evm' + }, url: `http://127.0.0.1:8545`, }, }, @@ -20127,15 +20073,15 @@ After testing your contract locally, you can deploy it to a live network. This g /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - ... + target: 'evm' }, - localNode: { + ... + polkadot: { + target: 'evm' ... }, polkadotHubTestnet: { - polkavm: true, + polkadot: true, url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', accounts: [vars.get('PRIVATE_KEY')], }, @@ -20154,7 +20100,7 @@ After testing your contract locally, you can deploy it to a live network. This g 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. -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`). +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. ```javascript title="interact.js" const hre = require('hardhat'); @@ -20211,7 +20157,7 @@ rm -rf node_modules package-lock.json After that, you can upgrade the plugin to the latest version by running the following commands: ```bash -npm install --save-dev @parity/hardhat-polkadot@latest +npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 npm install ``` diff --git a/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md b/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md index 9f7297b89..87c5076d2 100644 --- a/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md +++ b/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md @@ -34,8 +34,7 @@ Hardhat is a robust development environment for Ethereum-compatible chains that Before getting started, ensure you have: -- [Node.js](https://nodejs.org/){target=\_blank} (v16.0.0 or later) and npm installed. - - Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin. +- [Node.js](https://nodejs.org/){target=\_blank} (v22.5.0 or later) and npm installed. - Basic understanding of Solidity programming. - 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. @@ -57,7 +56,7 @@ Before getting started, ensure you have: 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: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 ``` 4. Create a Hardhat project: @@ -89,65 +88,13 @@ Before getting started, ensure you have: ## Compile Your Contract -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: - -- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use. -- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options. +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible. To compile your project, follow these instructions: -1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network: - - === "npm Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-11 14" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); - - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'npm', - }, - networks: { - hardhat: { - polkavm: true, - }, - }, - }; - ``` - - === "Binary Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-14 17" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); +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`. - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'binary', - settings: { - compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER', - }, - }, - networks: { - hardhat: { - polkavm: true, - }, - }, - }; - ``` - - 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. - - 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: + 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: ```javascript title="hardhat.config.js" hl_lines="4-10" resolc: { @@ -159,13 +106,12 @@ To compile your project, follow these instructions: fallbackOz: true, runs: 200, }, - standardJson: true, }, ... } ``` - 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. + 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. 2. Compile the contract with Hardhat: @@ -173,21 +119,21 @@ To compile your project, follow these instructions: npx hardhat compile ``` -3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory: +3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory: ```bash - ls artifacts-pvm/contracts/*.sol/ + ls artifacts/contracts/*.sol/ ``` You should see JSON files containing the contract ABI and bytecode of the contracts you compiled. ## Set Up a Testing Environment -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. +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. -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. +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. -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: +Configure a local node setup by adding the `anvil-polkadot` node binary path: ```javascript title="hardhat.config.js" hl_lines="12-20" // hardhat.config.js @@ -197,24 +143,24 @@ require('@parity/hardhat-polkadot'); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - polkavm: true, + target: 'evm' + }, nodeConfig: { - nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE', - rpcPort: 8000, - dev: true, + useAnvil: true, + nodeBinaryPath: 'INSERT_PATH_TO_ANVIL_NODE', }, adapterConfig: { adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER', dev: true, }, }, + localNode: { + polkadot: { }, }; ``` -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. +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. !!! warning 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. @@ -225,7 +171,7 @@ Once configured, start your chosen testing environment with: npx hardhat node ``` -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`. +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`. The output will be something like this: @@ -278,12 +224,12 @@ Before deploying to a live network, you can deploy your contract to a local node /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - ... + target: 'evm' }, - localNode: { - polkavm: true, + ... + polkadot: { + target: 'evm' + }, url: `http://127.0.0.1:8545`, }, }, @@ -340,15 +286,15 @@ After testing your contract locally, you can deploy it to a live network. This g /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { ... - networks: { - hardhat: { - ... + target: 'evm' }, - localNode: { + ... + polkadot: { + target: 'evm' ... }, polkadotHubTestnet: { - polkavm: true, + polkadot: true, url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', accounts: [vars.get('PRIVATE_KEY')], }, @@ -367,7 +313,7 @@ After testing your contract locally, you can deploy it to a live network. This g 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. -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`). +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. ```javascript title="interact.js" const hre = require('hardhat'); @@ -424,7 +370,7 @@ rm -rf node_modules package-lock.json After that, you can upgrade the plugin to the latest version by running the following commands: ```bash -npm install --save-dev @parity/hardhat-polkadot@latest +npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 npm install ``` diff --git a/.ai/site-index.json b/.ai/site-index.json index 08f3be47f..ceceeca71 100644 --- a/.ai/site-index.json +++ b/.ai/site-index.json @@ -2720,12 +2720,12 @@ } ], "stats": { - "chars": 18520, - "words": 2475, + "chars": 16382, + "words": 2255, "headings": 11, - "estimated_token_count_total": 4188 + "estimated_token_count_total": 3740 }, - "hash": "sha256:fe008393aa37c27bb71b4483d4e2c4fbcda94f8c1be461fdd07eff40efbb4e26", + "hash": "sha256:9fc45c5239ad2ecdff7e5b0f48a09220ab936d3614baeda875cfbd632ceb34a5", "token_estimator": "heuristic-v1" }, { diff --git a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js deleted file mode 100644 index b28b32e8d..000000000 --- a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js +++ /dev/null @@ -1,38 +0,0 @@ -// hardhat.config.js -require('@nomicfoundation/hardhat-toolbox'); - -require('@parity/hardhat-polkadot'); - -/** @type import('hardhat/config').HardhatUserConfig */ -module.exports = { - solidity: '0.8.28', - resolc: { - compilerSource: 'binary', - settings: { - compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER', - }, - }, - networks: { - hardhat: { - polkavm: true, - nodeConfig: { - nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE', - rpcPort: 8000, - dev: true, - }, - adapterConfig: { - adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER', - dev: true, - }, - }, - localNode: { - polkavm: true, - url: `http://127.0.0.1:8545`, - }, - polkadotHubTestnet: { - polkavm: true, - url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', - accounts: [process.env.PRIVATE_KEY], - }, - }, -}; diff --git a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js index 17adca66f..02e2d7ce3 100644 --- a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js +++ b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js @@ -6,16 +6,14 @@ require('@parity/hardhat-polkadot'); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: '0.8.28', - resolc: { - compilerSource: 'npm', - }, networks: { hardhat: { - polkavm: true, + polkadot: { + target: 'evm' + }, nodeConfig: { - nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE', - rpcPort: 8000, - dev: true, + useAnvil: true, + nodeBinaryPath: 'INSERT_PATH_TO_ANVIL_NODE', }, adapterConfig: { adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER', @@ -23,11 +21,13 @@ module.exports = { }, }, localNode: { - polkavm: true, + polkadot: { + target: 'evm' + }, url: `http://127.0.0.1:8545`, }, polkadotHubTestnet: { - polkavm: true, + polkadot: true, url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', accounts: [vars.get('PRIVATE_KEY')], }, diff --git a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/lock-ignition.js b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/lock-ignition.js deleted file mode 100644 index 02f42bda5..000000000 --- a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/lock-ignition.js +++ /dev/null @@ -1,18 +0,0 @@ -// This setup uses Hardhat Ignition to manage smart contract deployments. -// Learn more about it at https://hardhat.org/ignition - -const { buildModule } = require('@nomicfoundation/hardhat-ignition/modules'); - -const JAN_1ST_2030 = 18934560000000; -const ONE_GWEI = 1_000_000_000n; - -module.exports = buildModule('LockModule', (m) => { - const unlockTime = m.getParameter('unlockTime', JAN_1ST_2030); - const lockedAmount = m.getParameter('lockedAmount', ONE_GWEI); - - const lock = m.contract('Lock', [unlockTime], { - value: lockedAmount, - }); - - return { lock }; -}); diff --git a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/lock-test.js b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/lock-test.js deleted file mode 100644 index ad02bd6e6..000000000 --- a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/lock-test.js +++ /dev/null @@ -1,47 +0,0 @@ -const { expect } = require('chai'); -const { ethers } = require('hardhat'); - -describe('Lock', function () { - let owner, otherAccount; - - beforeEach(async function () { - [owner, otherAccount] = await ethers.getSigners(); - }); - - const FAR_FUTURE_TIME = 10 ** 13; - const ONE_GWEI = 1_000_000_000; - - it('Should deploy successfully with future unlock time', async function () { - // Deploy with a timestamp far in the future - const Lock = await ethers.getContractFactory('Lock'); - const lock = await Lock.deploy(FAR_FUTURE_TIME, { value: ONE_GWEI }); - - // Verify the contract was deployed successfully - expect(await lock.unlockTime()).to.equal(FAR_FUTURE_TIME); - expect(await lock.owner()).to.equal(owner.address); - expect(await ethers.provider.getBalance(lock.target)).to.equal(ONE_GWEI); - }); - - it('Should fail if unlock time is not in the future', async function () { - // Use a timestamp in the past - const PAST_TIME = Math.floor(Date.now() / 1000) - 1000; - - const Lock = await ethers.getContractFactory('Lock'); - - // This should be reverted due to the past timestamp - await expect( - Lock.deploy(PAST_TIME, { value: ONE_GWEI }) - ).to.be.revertedWith('Unlock time should be in the future'); - }); - - it('Should not allow non-owners to withdraw', async function () { - // Deploy with a future timestamp - const Lock = await ethers.getContractFactory('Lock'); - const lock = await Lock.deploy(FAR_FUTURE_TIME, { value: ONE_GWEI }); - - // Try to withdraw as non-owner - await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith( - "You can't withdraw yet" - ); - }); -}); diff --git a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/my-token-ignition.js b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/my-token-ignition.js new file mode 100644 index 000000000..12d7449a5 --- /dev/null +++ b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/my-token-ignition.js @@ -0,0 +1,14 @@ +// This setup uses Hardhat Ignition to manage smart contract deployments. +// Learn more about it at https://hardhat.org/ignition + +const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules") + +const MyTokenModule = buildModule("MyTokenModule", (m) => { + const initialSupply = m.getParameter("initialSupply", 1000000n * 10n ** 18n) + + const token = m.contract("MyToken", [initialSupply]) + + return { token } +}) + +module.exports = MyTokenModule diff --git a/.snippets/code/develop/smart-contracts/dev-environments/hardhat/my-token-test.js b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/my-token-test.js new file mode 100644 index 000000000..f87fcd21b --- /dev/null +++ b/.snippets/code/develop/smart-contracts/dev-environments/hardhat/my-token-test.js @@ -0,0 +1,69 @@ +const { expect } = require("chai") +const { ethers } = require("hardhat") + +describe("MyToken", function () { + let token, owner, addr1, addr2 + const initialSupply = ethers.parseUnits("1000000", 18) // 1M tokens + + beforeEach(async () => { + ;[owner, addr1, addr2] = await ethers.getSigners() + + const MyToken = await ethers.getContractFactory("MyToken") + token = await MyToken.deploy(initialSupply) + await token.waitForDeployment() + }) + + it("should assign the initial supply to the deployer", async () => { + const balance = await token.balanceOf(owner.address) + expect(balance).to.equal(initialSupply) + }) + + it("should allow minting by MINTER_ROLE", async () => { + const amount = ethers.parseUnits("1000", 18) + await token.mint(addr1.address, amount) + expect(await token.balanceOf(addr1.address)).to.equal(amount) + }) + + it("should not allow minting by non-minters", async () => { + const amount = ethers.parseUnits("1000", 18) + await expect(token.connect(addr1).mint(addr2.address, amount)) + .to.be.revertedWithCustomError(token, "AccessControlUnauthorizedAccount") + .withArgs(addr1.address, await token.MINTER_ROLE()) + }) + + it("should allow burning tokens", async () => { + const burnAmount = ethers.parseUnits("500", 18) + await token.burn(burnAmount) + const balance = await token.balanceOf(owner.address) + expect(balance).to.equal(initialSupply - burnAmount) + }) + + it("should allow pausing by PAUSER_ROLE", async () => { + await token.pause() + await expect(token.transfer(addr1.address, 1)).to.be.revertedWithCustomError( + token, + "EnforcedPause", + ) + }) + + it("should not allow pausing by non-pauser", async () => { + const PAUSER_ROLE = await token.PAUSER_ROLE() + + await expect(token.connect(addr1).pause()) + .to.be.revertedWithCustomError(token, "AccessControlUnauthorizedAccount") + .withArgs(addr1.address, PAUSER_ROLE) + }) + + it("should allow unpausing", async () => { + await token.pause() + await token.unpause() + await expect(token.transfer(addr1.address, 100)).to.not.be.reverted + }) + + it("should assign roles correctly", async () => { + const MINTER_ROLE = await token.MINTER_ROLE() + const PAUSER_ROLE = await token.PAUSER_ROLE() + expect(await token.hasRole(MINTER_ROLE, owner.address)).to.be.true + expect(await token.hasRole(PAUSER_ROLE, owner.address)).to.be.true + }) +}) diff --git a/develop/smart-contracts/dev-environments/hardhat.md b/develop/smart-contracts/dev-environments/hardhat.md index bb407c951..bd8d1863a 100644 --- a/develop/smart-contracts/dev-environments/hardhat.md +++ b/develop/smart-contracts/dev-environments/hardhat.md @@ -30,8 +30,7 @@ Hardhat is a robust development environment for Ethereum-compatible chains that Before getting started, ensure you have: -- [Node.js](https://nodejs.org/){target=\_blank} (v16.0.0 or later) and npm installed. - - Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin. +- [Node.js](https://nodejs.org/){target=\_blank} (v22.5.0 or later) and npm installed. - Basic understanding of Solidity programming. - 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. @@ -53,7 +52,7 @@ Before getting started, ensure you have: 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: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 ``` 4. Create a Hardhat project: @@ -85,32 +84,13 @@ Before getting started, ensure you have: ## Compile Your Contract -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: - -- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use. -- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options. +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible. To compile your project, follow these instructions: -1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network: - - === "npm Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-11 14" - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:14' - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:33:35' - ``` - - === "Binary Configuration" - - ```javascript title="hardhat.config.js" hl_lines="9-14 17" - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js:1:17' - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/binary-hardhat.config.js:36:38' - ``` - - 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. +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`. - 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: + 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: ```javascript title="hardhat.config.js" hl_lines="4-10" resolc: { @@ -122,13 +102,12 @@ To compile your project, follow these instructions: fallbackOz: true, runs: 200, }, - standardJson: true, }, ... } ``` - 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. + 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. 2. Compile the contract with Hardhat: @@ -136,21 +115,21 @@ To compile your project, follow these instructions: npx hardhat compile ``` -3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory: +3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory: ```bash - ls artifacts-pvm/contracts/*.sol/ + ls artifacts/contracts/*.sol/ ``` You should see JSON files containing the contract ABI and bytecode of the contracts you compiled. ## Set Up a Testing Environment -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. +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. -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. +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. -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: +Configure a local node setup by adding the `anvil-polkadot` node binary path: ```javascript title="hardhat.config.js" hl_lines="12-20" --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4' @@ -161,7 +140,7 @@ Configure a local node setup by adding the node binary path along with the ETH-R --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:34:35' ``` -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. +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. !!! warning 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. @@ -172,7 +151,7 @@ Once configured, start your chosen testing environment with: npx hardhat node ``` -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`. +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`. The output will be something like this: @@ -274,7 +253,7 @@ After testing your contract locally, you can deploy it to a live network. This g 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. -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`). +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. ```javascript title="interact.js" --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/interact.js' @@ -297,7 +276,7 @@ rm -rf node_modules package-lock.json After that, you can upgrade the plugin to the latest version by running the following commands: ```bash -npm install --save-dev @parity/hardhat-polkadot@latest +npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6 npm install ``` diff --git a/llms-full.jsonl b/llms-full.jsonl index 69c17b5df..583147104 100644 --- a/llms-full.jsonl +++ b/llms-full.jsonl @@ -313,16 +313,16 @@ {"page_id": "develop-smart-contracts-dev-environments-foundry", "page_title": "Use Foundry with Polkadot Hub", "index": 9, "depth": 3, "title": "Forge Commands", "anchor": "forge-commands", "start_char": 7544, "end_char": 13032, "estimated_token_count": 1502, "token_estimator": "heuristic-v1", "text": "### Forge Commands\n\n- **`init`**:\n - **Command**: `forge init `.\n - **Description**: Initializes a new Foundry project in the current directory, setting up the basic project structure and installing standard libraries.\n\n- **`bind`**:\n - **Command**: `forge bind [--resolc]`.\n - **Description**: Generates type-safe Rust bindings for your Solidity contracts. Use `--resolc` to ensure compilation with the `resolc` compiler for PolkaVM compatibility.\n\n- **`bind-json`**:\n - **Command**: `forge bind-json [--resolc]`.\n - **Description**: Generates JSON bindings for your Solidity contracts. Use `--resolc` for `resolc`-based compilation.\n\n- **`build`**:\n - **Command**: `forge build [--resolc]`.\n - **Description**: Compiles all Solidity contracts in your project. Specify `--resolc` to compile for PolkaVM.\n\n- **`cache clean`**:\n - **Command**: `forge cache clean`.\n - **Description**: Clears the Foundry cache directory.\n\n- **`cache ls`**:\n - **Command**: `forge cache ls`.\n - **Description**: Lists the contents of the Foundry cache.\n\n- **`clean`**:\n - **Command**: `forge clean`.\n - **Description**: Removes all build artifacts from the project's `out` directory.\n\n- **`compiler resolve`**:\n - **Command**: `forge compiler resolve [--resolc]`.\n - **Description**: Resolves and displays the versions of Solidity compilers Foundry is using. Use `--resolc` to also check for `resolc`.\n\n- **`config`**:\n - **Command**: `forge config`.\n - **Description**: Displays the current Foundry project configuration, including settings from `foundry.toml`.\n\n- **`create`**:\n - **Command**: `forge create [OPTIONS] `.\n - **Required Parameters**: `` (the name of the contract to deploy).\n - **Description**: Deploys a new contract to a specified blockchain network. The `--resolc` flag ensures it's compiled for PolkaVM. You'll typically need to provide an RPC URL, a private key for the deployer account, and potentially constructor arguments.\n\n- **`doc`**:\n - **Command**: `forge doc`.\n - **Description**: Generates documentation for your Solidity contracts.\n\n- **`flatten`**:\n - **Command**: `forge flatten [OPTIONS] `.\n - **Required Parameters**: `` (the path to the Solidity file).\n - **Description**: Combines all imports of a Solidity file into a single file, useful for deployment or verification.\n\n- **`fmt`**:\n - **Command**: `forge fmt`.\n - **Description**: Formats Solidity code according to a predefined style.\n\n- **`geiger`**:\n - **Command**: `forge geiger `.\n - **Required Parameters**: `` (the path to the Solidity file).\n - **Description**: Analyzes Solidity code for potential security vulnerabilities and gas inefficiencies.\n\n- **`generate test`**:\n - **Command**: `forge generate test --contract-name `.\n - **Required Parameters**: `--contract-name ` (the name of the contract for which to generate a test).\n - **Description**: Creates a new test file with boilerplate code for a specified contract.\n\n- **`generate-fig-spec`**:\n - **Command**: `forge generate-fig-spec`.\n - **Description**: Generates a Fig specification for CLI autocompletion tools.\n\n- **`inspect`**:\n - **Command**: `forge inspect [--resolc]`.\n - **Required Parameters**: `` (the contract to inspect), `` (e.g., `bytecode`, `abi`, `methods`, `events`).\n - **Description**: Displays various artifacts of a compiled contract. Use `--resolc` to inspect `resolc`-compiled artifacts; the bytecode will start with `0x505`.\n\n- **`install`**:\n - **Command**: `forge install `.\n - **Description**: Installs a Solidity library or dependency from a Git repository.\n\n- **`update`**:\n - **Command**: `forge update []`.\n - **Description**: Updates installed dependencies. If a repository is specified, only that one is updated.\n\n- **`remappings`**:\n - **Command**: `forge remappings`.\n - **Description**: Lists the currently configured Solidity compiler remappings.\n\n- **`remove`**:\n - **Command**: `forge remove `.\n - **Description**: Removes an installed Solidity dependency. Use `--force` to remove without confirmation.\n\n- **`selectors upload`**:\n - **Command**: `forge selectors upload [--all]`.\n - **Description**: Uploads function selectors from compiled contracts to OpenChain. Use `--all` to upload for all contracts.\n\n- **`selectors list`**:\n - **Command**: `forge selectors list`.\n - **Description**: Lists all known function selectors for contracts in the project.\n\n- **`selectors find`**:\n - **Command**: `forge selectors find `.\n - **Description**: Searches for a function signature given its 4-byte selector.\n\n- **`selectors cache`**:\n - **Command**: `forge selectors cache`.\n - **Description**: Caches function selectors for faster lookup.\n\n- **`tree`**:\n - **Command**: `forge tree`.\n - **Description**: Displays the dependency tree of your Solidity contracts.\n\n!!!warning \"Non-working Commands\"\n\n Consider that some foundry commands are not yet supported in `foundry-polkadot`:\n\n - **`clone`**: This command is not supported in `foundry-polkadot`.\n - **`coverage`**: Code coverage analysis is not supported.\n - **`snapshot`**: Creating blockchain state snapshots is not supported.\n - **`test`**: Running Solidity tests is not supported."} {"page_id": "develop-smart-contracts-dev-environments-foundry", "page_title": "Use Foundry with Polkadot Hub", "index": 10, "depth": 3, "title": "Cast Commands", "anchor": "cast-commands", "start_char": 13032, "end_char": 23398, "estimated_token_count": 3084, "token_estimator": "heuristic-v1", "text": "### Cast Commands\n\n- **`4byte`**:\n - **Command**: `cast 4byte [OPTIONS] [TOPIC_0]`.\n - **Description**: Decodes a 4-byte function selector into its human-readable function signature.\n\n- **`4byte-event`**:\n - **Command**: `cast 4byte-event [OPTIONS] [TOPIC_0]`.\n - **Description**: Decodes a 4-byte event topic into its human-readable event signature.\n\n- **`abi-encode`**:\n - **Command**: `cast abi-encode [ARGS]...`.\n - **Required Parameters**: `` (the function signature), `[ARGS]` (arguments to encode).\n - **Description**: ABI-encodes function arguments according to a given signature.\n\n- **`address-zero`**:\n - **Command**: `cast address-zero`.\n - **Description**: Returns the zero address (0x00...00).\n\n- **`age`**:\n - **Command**: `cast age [OPTIONS] [BLOCK]`.\n - **Description**: Converts a block number or tag (e.g., `latest`) into its timestamp.\n\n- **`balance`**:\n - **Command**: `cast balance [OPTIONS] `.\n - **Required Parameters**: `` (the address to check).\n - **Description**: Retrieves the native token balance of a given address on the specified RPC network.\n\n- **`base-fee`**:\n - **Command**: `cast base-fee [OPTIONS] [BLOCK]`.\n - **Description**: Retrieves the base fee per gas for a specific block (defaults to `latest`).\n\n- **`block`**:\n - **Command**: `cast block [OPTIONS] [BLOCK]`.\n - **Description**: Retrieves comprehensive details about a specific block (defaults to `latest`).\n\n- **`block-number`**:\n - **Command**: `cast block-number [OPTIONS] [BLOCK]`.\n - **Description**: Retrieves the number of the latest or a specified block.\n\n- **`call`**:\n - **Command**: `cast call [OPTIONS] [ARGS]...`.\n - **Description**: Executes a read-only (constant) function call on a contract. No transaction is sent to the network.\n\n- **`chain`**:\n - **Command**: `cast chain [OPTIONS]`.\n - **Description**: Displays the human-readable name of the connected blockchain.\n\n- **`chain-id`**:\n - **Command**: `cast chain-id [OPTIONS]`.\n - **Description**: Displays the chain ID of the connected blockchain.\n\n- **`client`**:\n - **Command**: `cast client [OPTIONS]`.\n - **Description**: Retrieves information about the connected RPC client (node software).\n\n- **`code`**:\n - **Command**: `cast code [OPTIONS] `.\n - **Required Parameters**: `` (the contract address).\n - **Description**: Retrieves the bytecode deployed at a given contract address.\n\n- **`codesize`**:\n - **Command**: `cast codesize [OPTIONS] `.\n - **Required Parameters**: `` (the contract address).\n - **Description**: Retrieves the size of the bytecode deployed at a given contract address.\n\n- **`compute-address`**:\n - **Command**: `cast compute-address [OPTIONS] `.\n - **Required Parameters**: `` (the deployer's address).\n - **Description**: Computes the predicted contract address based on the deployer's address and nonce.\n\n- **`decode-abi`**:\n - **Command**: `cast decode-abi `.\n - **Required Parameters**: `` (the function signature), `` (the ABI-encoded data).\n - **Description**: Decodes ABI-encoded output data from a contract call given its signature.\n\n- **`decode-calldata`**:\n - **Command**: `cast decode-calldata `.\n - **Required Parameters**: `` (the function signature), `` (the raw calldata).\n - **Description**: Decodes raw calldata into human-readable arguments using a function signature.\n\n- **`decode-error`**:\n - **Command**: `cast decode-error [--sig ]`.\n - **Required Parameters**: `` (the error data).\n - **Description**: Decodes a custom error message from a transaction revert. You may need to provide the error signature.\n\n- **`decode-event`**:\n - **Command**: `cast decode-event [--sig ]`.\n - **Required Parameters**: `` (the event data).\n - **Description**: Decodes event data from a transaction log.\n\n- **`estimate`**:\n - **Command**: `cast estimate [OPTIONS] [TO] [SIG] [ARGS]...`.\n - **Required Parameters**: `[TO]` (the recipient address or contract), `[SIG]` (function signature), `[ARGS]` (arguments).\n - **Description**: Estimates the gas cost for a transaction or function call.\n\n- **`find-block`**:\n - **Command**: `cast find-block [OPTIONS] `.\n - **Required Parameters**: `` (a Unix timestamp).\n - **Description**: Finds the closest block number to a given Unix timestamp.\n\n- **`gas-price`**:\n - **Command**: `cast gas-price [OPTIONS]`.\n - **Description**: Retrieves the current average gas price on the network.\n\n- **`generate-fig-spec`**:\n - **Command**: `cast generate-fig-spec`.\n - **Description**: Generates a Fig specification for CLI autocompletion.\n\n- **`index-string`**:\n - **Command**: `cast index-string `.\n - **Description**: Computes the Keccak-256 hash of a string, useful for event topics.\n\n- **`index-erc7201`**:\n - **Command**: `cast index-erc7201 `.\n - **Description**: Computes the hash for an ERC-7201 identifier.\n\n- **`logs`**:\n - **Command**: `cast logs [OPTIONS] [SIG_OR_TOPIC] [TOPICS_OR_ARGS]...`.\n - **Required Parameters**: `[SIG_OR_TOPIC]` (a signature or topic hash).\n - **Description**: Filters and displays event logs from transactions.\n\n- **`max-int`**:\n - **Command**: `cast max-int`.\n - **Description**: Displays the maximum value for a signed 256-bit integer.\n\n- **`max-uint`**:\n - **Command**: `cast max-uint`.\n - **Description**: Displays the maximum value for an unsigned 256-bit integer.\n\n- **`min-int`**:\n - **Command**: `cast min-int`.\n - **Description**: Displays the minimum value for a signed 256-bit integer.\n\n- **`mktx`**:\n - **Command**: `cast mktx [OPTIONS] [TO] [SIG] [ARGS]...`.\n - **Required Parameters**: `[TO]` (the recipient address or contract).\n - **Description**: Creates a raw, signed transaction that can be broadcast later.\n\n- **`decode-transaction`**:\n - **Command**: `cast decode-transaction [OPTIONS] [TX]`.\n - **Required Parameters**: `[TX]` (the raw transaction hex string).\n - **Description**: Decodes a raw transaction hex string into its human-readable components.\n\n- **`namehash increment`**:\n - **Command**: `cast namehash `.\n - **Description**: Computes the ENS (Ethereum Name Service) namehash for a given name.\n\n- **`nonce`**:\n - **Command**: `cast nonce [OPTIONS] `.\n - **Required Parameters**: `` (the address to check).\n - **Description**: Retrieves the transaction count (nonce) for a given address.\n\n- **`parse-bytes32-address`**:\n - **Command**: `cast parse-bytes32-address `.\n - **Description**: Parses a 32-byte hex string (e.g., from `bytes32`) into an Ethereum address.\n\n- **`parse-bytes32-string`**:\n - **Command**: `cast parse-bytes32-string `.\n - **Description**: Parses a 32-byte hex string into a human-readable string.\n\n- **`parse-units`**:\n - **Command**: `cast parse-units [UNIT]`.\n - **Description**: Converts a human-readable amount into its smallest unit (e.g., Ether to Wei). Defaults to `ether`.\n\n- **`pretty-calldata`**:\n - **Command**: `cast pretty-calldata [OPTIONS] `.\n - **Required Parameters**: `` (the calldata hex string).\n - **Description**: Attempts to pretty-print and decode a raw calldata string into possible function calls.\n\n- **`publish`**:\n - **Command**: `cast publish [OPTIONS] `.\n - **Description**: Broadcasts a raw, signed transaction to the network.\n\n- **`receipt`**:\n - **Command**: `cast receipt [OPTIONS] `.\n - **Description**: Retrieves the transaction receipt for a given transaction hash, including status, gas usage, and logs.\n\n- **`rpc`**:\n - **Command**: `cast rpc [OPTIONS] [PARAMS]...`.\n - **Required Parameters**: `` (the RPC method to call), `[PARAMS]` (parameters for the method).\n - **Description**: Makes a direct RPC call to the connected blockchain node.\n\n- **`send`**:\n - **Command**: `cast send [OPTIONS] [ARGS]...`.\n - **Required Parameters**: `` (the recipient address or contract).\n - **Description**: Sends a transaction to a contract or address, executing a function or transferring value.\n\n- **`sig`**:\n - **Command**: `cast sig `.\n - **Required Parameters**: `` (the full function signature string).\n - **Description**: Computes the 4-byte function selector for a given function signature.\n\n- **`sig-event`**:\n - **Command**: `cast sig-event `.\n - **Required Parameters**: `` (the full event signature string).\n - **Description**: Computes the Keccak-256 hash (topic) for a given event signature.\n\n- **`storage`**:\n - **Command**: `cast storage [OPTIONS]
[SLOT]`.\n - **Required Parameters**: `
` (the contract address).\n - **Description**: Retrieves the raw value stored at a specific storage slot of a contract.\n\n- **`tx`**:\n - **Command**: `cast tx [OPTIONS] `.\n - **Description**: Retrieves comprehensive details about a specific transaction.\n\n- **`upload-signature`**:\n - **Command**: `cast upload-signature [OPTIONS] `.\n - **Required Parameters**: `` (the function or event signature).\n - **Description**: Uploads a function or event signature to the OpenChain registry.\n\n- **`wallet`**:\n - **Command**: `cast wallet new`.\n - **Description**: Generates a new random Ethereum keypair (private key and address).\n\n- **`wallet new-mnemonic`**:\n - **Command**: `cast wallet new-mnemonic`.\n - **Description**: Generates a new BIP-39 mnemonic phrase and derives the first account from it.\n\n- **`wallet address`**:\n - **Command**: `cast wallet address [OPTIONS]`.\n - **Description**: Derives and displays the Ethereum address from a private key or mnemonic (if provided).\n\n!!!warning \"Non-working Commands\"\n\n Consider that some foundry commands are not yet supported in `foundry-polkadot`:\n\n - **`proof`**: This command, used for generating Merkle proofs, is not supported.\n - **`storage-root`**: This command, used for retrieving the storage root of a contract, is not supported."} {"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 0, "depth": 2, "title": "Overview", "anchor": "overview", "start_char": 996, "end_char": 1270, "estimated_token_count": 47, "token_estimator": "heuristic-v1", "text": "## Overview\n\nHardhat is a robust development environment for Ethereum-compatible chains that makes smart contract development more efficient. This guide walks you through the essentials of using Hardhat to create, compile, test, and deploy smart contracts on Polkadot Hub."} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 1270, "end_char": 1862, "estimated_token_count": 164, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore getting started, ensure you have:\n\n- [Node.js](https://nodejs.org/){target=\\_blank} (v16.0.0 or later) and npm installed.\n - Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin.\n- Basic understanding of Solidity programming.\n- 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."} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 2, "depth": 2, "title": "Set Up Hardhat", "anchor": "set-up-hardhat", "start_char": 1862, "end_char": 3279, "estimated_token_count": 317, "token_estimator": "heuristic-v1", "text": "## Set Up Hardhat\n\n1. Create a new directory for your project and navigate into it:\n\n ```bash\n mkdir hardhat-example\n cd hardhat-example\n ```\n\n2. Initialize a new npm project:\n\n ```bash\n npm init -y\n ```\n\n3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts to PolkaVM bytecode and to spawn a local node compatible with PolkaVM:\n\n ```bash\n npm install --save-dev @parity/hardhat-polkadot@0.1.9\n ```\n\n4. Create a Hardhat project:\n\n ```bash\n npx hardhat-polkadot init\n ```\n\n Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders:\n\n - **`contracts`**: Where your Solidity smart contracts live.\n - **`test`**: Contains your test files that validate contract functionality.\n - **`ignition`**: Deployment modules for safely deploying your contracts to various networks.\n\n5. Add the following folder to the `.gitignore` file if it is not already there:\n\n ```bash\n echo '/ignition/deployments/' >> .gitignore\n ```\n\n6. Finish the setup by installing all the dependencies:\n\n ```bash\n npm install\n ```\n\n !!! note\n This last step is needed to set up the `hardhat-polkadot` plugin. It will install the `@parity/hardhat-polkadot` package and all its dependencies. In the future, the plugin will handle this automatically."} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 3, "depth": 2, "title": "Compile Your Contract", "anchor": "compile-your-contract", "start_char": 3279, "end_char": 6677, "estimated_token_count": 763, "token_estimator": "heuristic-v1", "text": "## Compile Your Contract\n\nThe 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:\n\n- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\\_blank} for simplicity and ease of use.\n- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options.\n\nTo compile your project, follow these instructions:\n\n1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network:\n\n === \"npm Configuration\"\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"9-11 14\"\n // hardhat.config.js\n require('@nomicfoundation/hardhat-toolbox');\n\n require('@parity/hardhat-polkadot');\n\n /** @type import('hardhat/config').HardhatUserConfig */\n module.exports = {\n solidity: '0.8.28',\n resolc: {\n compilerSource: 'npm',\n },\n networks: {\n hardhat: {\n polkavm: true,\n },\n },\n };\n ```\n\n === \"Binary Configuration\"\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"9-14 17\"\n // hardhat.config.js\n require('@nomicfoundation/hardhat-toolbox');\n\n require('@parity/hardhat-polkadot');\n\n /** @type import('hardhat/config').HardhatUserConfig */\n module.exports = {\n solidity: '0.8.28',\n resolc: {\n compilerSource: 'binary',\n settings: {\n compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER',\n },\n },\n networks: {\n hardhat: {\n polkavm: true,\n },\n },\n };\n ```\n\n 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.\n\n 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:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"4-10\"\n resolc: {\n ...\n settings: {\n optimizer: {\n enabled: true,\n parameters: 'z',\n fallbackOz: true,\n runs: 200,\n },\n standardJson: true,\n },\n ...\n }\n ```\n\n 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.\n\n2. Compile the contract with Hardhat:\n\n ```bash\n npx hardhat compile\n ```\n\n3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory:\n\n ```bash\n ls artifacts-pvm/contracts/*.sol/\n ```\n\n You should see JSON files containing the contract ABI and bytecode of the contracts you compiled."} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 4, "depth": 2, "title": "Set Up a Testing Environment", "anchor": "set-up-a-testing-environment", "start_char": 6677, "end_char": 10727, "estimated_token_count": 1066, "token_estimator": "heuristic-v1", "text": "## Set Up a Testing Environment\n\nHardhat 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.\n\nFor 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.\n\nConfigure a local node setup by adding the node binary path along with the ETH-RPC adapter path:\n\n```javascript title=\"hardhat.config.js\" hl_lines=\"12-20\"\n// hardhat.config.js\nrequire('@nomicfoundation/hardhat-toolbox');\n\nrequire('@parity/hardhat-polkadot');\n/** @type import('hardhat/config').HardhatUserConfig */\nmodule.exports = {\n ...\n networks: {\n hardhat: {\n polkavm: true,\n nodeConfig: {\n nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE',\n rpcPort: 8000,\n dev: true,\n },\n adapterConfig: {\n adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',\n dev: true,\n },\n },\n },\n};\n```\n\nReplace `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.\n\n!!! warning\n 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.\n\nOnce configured, start your chosen testing environment with:\n\n```bash\nnpx hardhat node\n```\n\nThis 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`.\n\nThe output will be something like this:\n\n
\n npx hardhat node\n
\n Starting server at 127.0.0.1:8000\n ../bin/substrate-node --rpc-port=8000 --dev\n Starting the Eth RPC Adapter at 127.0.0.1:8545\n ../bin/eth-rpc --node-rpc-url=ws://localhost:8000 --dev\n 2025-05-29 13:00:32 Running in --dev mode, RPC CORS has been disabled.\n 2025-05-29 13:00:32 Running in --dev mode, RPC CORS has been disabled.\n 2025-05-29 13:00:32 🌐 Connecting to node at: ws://localhost:8000 ...\n 2025-05-29 13:00:32 Substrate Node\n 2025-05-29 13:00:32 ✌️ version 3.0.0-dev-f73c228b7a1\n 2025-05-29 13:00:32 ❤️ by Parity Technologies <admin@parity.io>, 2017-2025\n 2025-05-29 13:00:32 📋 Chain specification: Development\n 2025-05-29 13:00:32 🏷 Node name: electric-activity-4221\n 2025-05-29 13:00:32 👤 Role: AUTHORITY\n 2025-05-29 13:00:32 💾 Database: RocksDb at /var/folders/f4/7rdt2m9d7j361dm453cpggbm0000gn/T/substrateOaoecu/chains/dev/db/full\n 2025-05-29 13:00:36 [0] 💸 generated 1 npos voters, 1 from validators and 0 nominators\n ...\n
"} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 5, "depth": 2, "title": "Test Your Contract", "anchor": "test-your-contract", "start_char": 10727, "end_char": 11626, "estimated_token_count": 224, "token_estimator": "heuristic-v1", "text": "## Test Your Contract\n\nWhen testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/network-helpers`](https://hardhat.org/hardhat-network-helpers/docs/overview){target=\\_blank} is not fully compatible with Polkadot Hub's available RPCs. Specifically, Hardhat-only helpers like `time` and `loadFixture` may not work due to missing RPC calls in the node. For more details, refer to the [Compatibility](https://github.com/paritytech/hardhat-polkadot/tree/main/packages/hardhat-polkadot-node#compatibility){target=\\_blank} section in the `hardhat-revive` docs. You should avoid using helpers like `time` and `loadFixture` when writing tests.\n\nTo run your test:\n\n1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section.\n\n2. Execute the following command to run your tests:\n\n ```bash\n npx hardhat test\n ```"} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 6, "depth": 2, "title": "Deploy to a Local Node", "anchor": "deploy-to-a-local-node", "start_char": 11626, "end_char": 12764, "estimated_token_count": 267, "token_estimator": "heuristic-v1", "text": "## Deploy to a Local Node\n\nBefore 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:\n\n1. Update the Hardhat configuration file to add the local network as a target for local deployment:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"13-16\"\n // hardhat.config.js\n require('@nomicfoundation/hardhat-toolbox');\n\n require('@parity/hardhat-polkadot');\n /** @type import('hardhat/config').HardhatUserConfig */\n module.exports = {\n ...\n networks: {\n hardhat: {\n ...\n },\n localNode: {\n polkavm: true,\n url: `http://127.0.0.1:8545`,\n },\n },\n },\n };\n ```\n\n2. Start a local node:\n\n ```bash\n npx hardhat node\n ```\n\n This command will spawn a local Substrate node along with the ETH-RPC adapter.\n\n3. In a new terminal window, deploy the contract using Ignition:\n\n ```bash\n npx hardhat ignition deploy ./ignition/modules/MyToken.js --network localNode\n ```"} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 7, "depth": 2, "title": "Deploying to a Live Network", "anchor": "deploying-to-a-live-network", "start_char": 12764, "end_char": 14980, "estimated_token_count": 489, "token_estimator": "heuristic-v1", "text": "## Deploying to a Live Network\n\nAfter testing your contract locally, you can deploy it to a live network. This guide will use the Polkadot Hub TestNet as the target network. Here's how to configure and deploy:\n\n1. Fund your deployment account with enough tokens to cover gas fees. In this case, the needed tokens are PAS (on Polkadot Hub TestNet). You can use the [Polkadot faucet](https://faucet.polkadot.io/?parachain=1111){target=\\_blank} to obtain testing tokens.\n\n2. Export your private key and save it in your Hardhat environment:\n\n ```bash\n npx hardhat vars set PRIVATE_KEY \"INSERT_PRIVATE_KEY\"\n ```\n\n Replace `INSERT_PRIVATE_KEY` with your actual private key. For further details on private key exportation, refer to the article [How to export an account's private key](https://support.metamask.io/configure/accounts/how-to-export-an-accounts-private-key/){target=\\_blank}.\n\n !!! warning\n Never reveal your private key, otherwise anyone with access to it can control your wallet and steal your funds. Store it securely and never share it publicly or commit it to version control systems.\n\n3. Check that your private key has been set up successfully by running:\n\n ```bash\n npx hardhat vars get PRIVATE_KEY\n ```\n\n4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"18-22\"\n // hardhat.config.js\n require('@nomicfoundation/hardhat-toolbox');\n\n require('@parity/hardhat-polkadot');\n const { vars } = require('hardhat/config');\n\n /** @type import('hardhat/config').HardhatUserConfig */\n module.exports = {\n ...\n networks: {\n hardhat: {\n ...\n },\n localNode: {\n ...\n },\n polkadotHubTestnet: {\n polkavm: true,\n url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',\n accounts: [vars.get('PRIVATE_KEY')],\n },\n },\n },\n };\n ```\n\n6. Deploy your contract using Ignition:\n\n ```bash\n npx hardhat ignition deploy ./ignition/modules/MyToken.js --network polkadotHubTestnet\n ```"} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 8, "depth": 2, "title": "Interacting with Your Contract", "anchor": "interacting-with-your-contract", "start_char": 14980, "end_char": 16780, "estimated_token_count": 426, "token_estimator": "heuristic-v1", "text": "## Interacting with Your Contract\n\nOnce 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.\n\nFor 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`).\n\n```javascript title=\"interact.js\"\nconst hre = require('hardhat');\n\nasync function main() {\n // Get the contract factory\n const MyToken = await hre.ethers.getContractFactory('MyToken');\n\n // Replace with your deployed contract address\n const contractAddress = 'INSERT_CONTRACT_ADDRESS';\n\n // Attach to existing contract\n const token = await MyToken.attach(contractAddress);\n\n // Get signers\n const [deployer] = await hre.ethers.getSigners();\n\n // Read contract state\n const name = await token.name();\n const symbol = await token.symbol();\n const totalSupply = await token.totalSupply();\n const balance = await token.balanceOf(deployer.address);\n\n console.log(`Token: ${name} (${symbol})`);\n console.log(\n `Total Supply: ${hre.ethers.formatUnits(totalSupply, 18)} tokens`,\n );\n console.log(\n `Deployer Balance: ${hre.ethers.formatUnits(balance, 18)} tokens`,\n );\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exitCode = 1;\n});\n\n```\n\nRun your interaction script:\n\n```bash\nnpx hardhat run scripts/interact.js --network polkadotHubTestnet\n```"} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 9, "depth": 2, "title": "Upgrading the Plugin", "anchor": "upgrading-the-plugin", "start_char": 16780, "end_char": 17440, "estimated_token_count": 176, "token_estimator": "heuristic-v1", "text": "## Upgrading the Plugin\n\nIf you already have a Hardhat Polkadot project and want to upgrade to a newer version of the plugin, to avoid errors (for example, `Cannot find module 'run-container'`), you can clean your dependencies by running the following commands:\n\n```bash\nrm -rf node_modules package-lock.json\n```\n\nAfter that, you can upgrade the plugin to the latest version by running the following commands:\n\n```bash\nnpm install --save-dev @parity/hardhat-polkadot@latest\nnpm install\n```\n\nConsider using [Node.js](https://nodejs.org/){target=\\_blank} 22.18+ and [npm](https://www.npmjs.com/){target=\\_blank} version 10.9.0+ to avoid issues with the plugin."} -{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 10, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 17440, "end_char": 18520, "estimated_token_count": 249, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\nHardhat provides a powerful environment for developing, testing, and deploying smart contracts on Polkadot Hub. Its plugin architecture allows seamless integration with PolkaVM through the `hardhat-resolc` and `hardhat-revive-node` plugins.\n\nExplore more about smart contracts through these resources:\n\n
\n\n- Guide __Smart Contracts on Polkadot__\n\n ---\n\n Dive into advanced smart contract concepts.\n\n [:octicons-arrow-right-24: Get Started](/develop/smart-contracts/)\n\n- External __Hardhat Documentation__\n\n ---\n\n Learn more about Hardhat's advanced features and best practices.\n\n [:octicons-arrow-right-24: Get Started](https://hardhat.org/docs){target=\\_blank}\n\n- External __OpenZeppelin Contracts__\n\n ---\n\n Test your skills by deploying contracts with prebuilt templates.\n\n [:octicons-arrow-right-24: Get Started](https://www.openzeppelin.com/solidity-contracts){target=\\_blank}\n\n
"} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 1270, "end_char": 1766, "estimated_token_count": 136, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore getting started, ensure you have:\n\n- [Node.js](https://nodejs.org/){target=\\_blank} (v22.5.0 or later) and npm installed.\n- Basic understanding of Solidity programming.\n- 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."} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 2, "depth": 2, "title": "Set Up Hardhat", "anchor": "set-up-hardhat", "start_char": 1766, "end_char": 3188, "estimated_token_count": 319, "token_estimator": "heuristic-v1", "text": "## Set Up Hardhat\n\n1. Create a new directory for your project and navigate into it:\n\n ```bash\n mkdir hardhat-example\n cd hardhat-example\n ```\n\n2. Initialize a new npm project:\n\n ```bash\n npm init -y\n ```\n\n3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts to PolkaVM bytecode and to spawn a local node compatible with PolkaVM:\n\n ```bash\n npm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6\n ```\n\n4. Create a Hardhat project:\n\n ```bash\n npx hardhat-polkadot init\n ```\n\n Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders:\n\n - **`contracts`**: Where your Solidity smart contracts live.\n - **`test`**: Contains your test files that validate contract functionality.\n - **`ignition`**: Deployment modules for safely deploying your contracts to various networks.\n\n5. Add the following folder to the `.gitignore` file if it is not already there:\n\n ```bash\n echo '/ignition/deployments/' >> .gitignore\n ```\n\n6. Finish the setup by installing all the dependencies:\n\n ```bash\n npm install\n ```\n\n !!! note\n This last step is needed to set up the `hardhat-polkadot` plugin. It will install the `@parity/hardhat-polkadot` package and all its dependencies. In the future, the plugin will handle this automatically."} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 3, "depth": 2, "title": "Compile Your Contract", "anchor": "compile-your-contract", "start_char": 3188, "end_char": 4882, "estimated_token_count": 392, "token_estimator": "heuristic-v1", "text": "## Compile Your Contract\n\nThe plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible.\n\nTo compile your project, follow these instructions:\n\n1. 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`.\n\n 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:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"4-10\"\n resolc: {\n ...\n settings: {\n optimizer: {\n enabled: true,\n parameters: 'z',\n fallbackOz: true,\n runs: 200,\n },\n },\n ...\n }\n ```\n\n 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.\n\n2. Compile the contract with Hardhat:\n\n ```bash\n npx hardhat compile\n ```\n\n3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory:\n\n ```bash\n ls artifacts/contracts/*.sol/\n ```\n\n You should see JSON files containing the contract ABI and bytecode of the contracts you compiled."} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 4, "depth": 2, "title": "Set Up a Testing Environment", "anchor": "set-up-a-testing-environment", "start_char": 4882, "end_char": 8756, "estimated_token_count": 1045, "token_estimator": "heuristic-v1", "text": "## Set Up a Testing Environment\n\nHardhat 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.\n\nFor 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.\n\nConfigure a local node setup by adding the `anvil-polkadot` node binary path:\n\n```javascript title=\"hardhat.config.js\" hl_lines=\"12-20\"\n// hardhat.config.js\nrequire('@nomicfoundation/hardhat-toolbox');\n\nrequire('@parity/hardhat-polkadot');\n/** @type import('hardhat/config').HardhatUserConfig */\nmodule.exports = {\n ...\n target: 'evm'\n },\n nodeConfig: {\n useAnvil: true,\n nodeBinaryPath: 'INSERT_PATH_TO_ANVIL_NODE',\n },\n adapterConfig: {\n adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',\n dev: true,\n },\n },\n localNode: {\n polkadot: {\n },\n};\n```\n\nReplace `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.\n\n!!! warning\n 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.\n\nOnce configured, start your chosen testing environment with:\n\n```bash\nnpx hardhat node\n```\n\nThis 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`.\n\nThe output will be something like this:\n\n
\n npx hardhat node\n
\n Starting server at 127.0.0.1:8000\n ../bin/substrate-node --rpc-port=8000 --dev\n Starting the Eth RPC Adapter at 127.0.0.1:8545\n ../bin/eth-rpc --node-rpc-url=ws://localhost:8000 --dev\n 2025-05-29 13:00:32 Running in --dev mode, RPC CORS has been disabled.\n 2025-05-29 13:00:32 Running in --dev mode, RPC CORS has been disabled.\n 2025-05-29 13:00:32 🌐 Connecting to node at: ws://localhost:8000 ...\n 2025-05-29 13:00:32 Substrate Node\n 2025-05-29 13:00:32 ✌️ version 3.0.0-dev-f73c228b7a1\n 2025-05-29 13:00:32 ❤️ by Parity Technologies <admin@parity.io>, 2017-2025\n 2025-05-29 13:00:32 📋 Chain specification: Development\n 2025-05-29 13:00:32 🏷 Node name: electric-activity-4221\n 2025-05-29 13:00:32 👤 Role: AUTHORITY\n 2025-05-29 13:00:32 💾 Database: RocksDb at /var/folders/f4/7rdt2m9d7j361dm453cpggbm0000gn/T/substrateOaoecu/chains/dev/db/full\n 2025-05-29 13:00:36 [0] 💸 generated 1 npos voters, 1 from validators and 0 nominators\n ...\n
"} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 5, "depth": 2, "title": "Test Your Contract", "anchor": "test-your-contract", "start_char": 8756, "end_char": 9655, "estimated_token_count": 224, "token_estimator": "heuristic-v1", "text": "## Test Your Contract\n\nWhen testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/network-helpers`](https://hardhat.org/hardhat-network-helpers/docs/overview){target=\\_blank} is not fully compatible with Polkadot Hub's available RPCs. Specifically, Hardhat-only helpers like `time` and `loadFixture` may not work due to missing RPC calls in the node. For more details, refer to the [Compatibility](https://github.com/paritytech/hardhat-polkadot/tree/main/packages/hardhat-polkadot-node#compatibility){target=\\_blank} section in the `hardhat-revive` docs. You should avoid using helpers like `time` and `loadFixture` when writing tests.\n\nTo run your test:\n\n1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section.\n\n2. Execute the following command to run your tests:\n\n ```bash\n npx hardhat test\n ```"} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 6, "depth": 2, "title": "Deploy to a Local Node", "anchor": "deploy-to-a-local-node", "start_char": 9655, "end_char": 10799, "estimated_token_count": 269, "token_estimator": "heuristic-v1", "text": "## Deploy to a Local Node\n\nBefore 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:\n\n1. Update the Hardhat configuration file to add the local network as a target for local deployment:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"13-16\"\n // hardhat.config.js\n require('@nomicfoundation/hardhat-toolbox');\n\n require('@parity/hardhat-polkadot');\n /** @type import('hardhat/config').HardhatUserConfig */\n module.exports = {\n ...\n target: 'evm'\n },\n ...\n polkadot: {\n target: 'evm'\n },\n url: `http://127.0.0.1:8545`,\n },\n },\n },\n };\n ```\n\n2. Start a local node:\n\n ```bash\n npx hardhat node\n ```\n\n This command will spawn a local Substrate node along with the ETH-RPC adapter.\n\n3. In a new terminal window, deploy the contract using Ignition:\n\n ```bash\n npx hardhat ignition deploy ./ignition/modules/MyToken.js --network localNode\n ```"} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 7, "depth": 2, "title": "Deploying to a Live Network", "anchor": "deploying-to-a-live-network", "start_char": 10799, "end_char": 13034, "estimated_token_count": 493, "token_estimator": "heuristic-v1", "text": "## Deploying to a Live Network\n\nAfter testing your contract locally, you can deploy it to a live network. This guide will use the Polkadot Hub TestNet as the target network. Here's how to configure and deploy:\n\n1. Fund your deployment account with enough tokens to cover gas fees. In this case, the needed tokens are PAS (on Polkadot Hub TestNet). You can use the [Polkadot faucet](https://faucet.polkadot.io/?parachain=1111){target=\\_blank} to obtain testing tokens.\n\n2. Export your private key and save it in your Hardhat environment:\n\n ```bash\n npx hardhat vars set PRIVATE_KEY \"INSERT_PRIVATE_KEY\"\n ```\n\n Replace `INSERT_PRIVATE_KEY` with your actual private key. For further details on private key exportation, refer to the article [How to export an account's private key](https://support.metamask.io/configure/accounts/how-to-export-an-accounts-private-key/){target=\\_blank}.\n\n !!! warning\n Never reveal your private key, otherwise anyone with access to it can control your wallet and steal your funds. Store it securely and never share it publicly or commit it to version control systems.\n\n3. Check that your private key has been set up successfully by running:\n\n ```bash\n npx hardhat vars get PRIVATE_KEY\n ```\n\n4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"18-22\"\n // hardhat.config.js\n require('@nomicfoundation/hardhat-toolbox');\n\n require('@parity/hardhat-polkadot');\n const { vars } = require('hardhat/config');\n\n /** @type import('hardhat/config').HardhatUserConfig */\n module.exports = {\n ...\n target: 'evm'\n },\n ...\n polkadot: {\n target: 'evm'\n ...\n },\n polkadotHubTestnet: {\n polkadot: true,\n url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',\n accounts: [vars.get('PRIVATE_KEY')],\n },\n },\n },\n };\n ```\n\n6. Deploy your contract using Ignition:\n\n ```bash\n npx hardhat ignition deploy ./ignition/modules/MyToken.js --network polkadotHubTestnet\n ```"} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 8, "depth": 2, "title": "Interacting with Your Contract", "anchor": "interacting-with-your-contract", "start_char": 13034, "end_char": 14638, "estimated_token_count": 384, "token_estimator": "heuristic-v1", "text": "## Interacting with Your Contract\n\nOnce 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.\n\nFor 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.\n\n```javascript title=\"interact.js\"\nconst hre = require('hardhat');\n\nasync function main() {\n // Get the contract factory\n const MyToken = await hre.ethers.getContractFactory('MyToken');\n\n // Replace with your deployed contract address\n const contractAddress = 'INSERT_CONTRACT_ADDRESS';\n\n // Attach to existing contract\n const token = await MyToken.attach(contractAddress);\n\n // Get signers\n const [deployer] = await hre.ethers.getSigners();\n\n // Read contract state\n const name = await token.name();\n const symbol = await token.symbol();\n const totalSupply = await token.totalSupply();\n const balance = await token.balanceOf(deployer.address);\n\n console.log(`Token: ${name} (${symbol})`);\n console.log(\n `Total Supply: ${hre.ethers.formatUnits(totalSupply, 18)} tokens`,\n );\n console.log(\n `Deployer Balance: ${hre.ethers.formatUnits(balance, 18)} tokens`,\n );\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exitCode = 1;\n});\n\n```\n\nRun your interaction script:\n\n```bash\nnpx hardhat run scripts/interact.js --network polkadotHubTestnet\n```"} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 9, "depth": 2, "title": "Upgrading the Plugin", "anchor": "upgrading-the-plugin", "start_char": 14638, "end_char": 15302, "estimated_token_count": 182, "token_estimator": "heuristic-v1", "text": "## Upgrading the Plugin\n\nIf you already have a Hardhat Polkadot project and want to upgrade to a newer version of the plugin, to avoid errors (for example, `Cannot find module 'run-container'`), you can clean your dependencies by running the following commands:\n\n```bash\nrm -rf node_modules package-lock.json\n```\n\nAfter that, you can upgrade the plugin to the latest version by running the following commands:\n\n```bash\nnpm install --save-dev @parity/hardhat-polkadot@0.2.0-pre6\nnpm install\n```\n\nConsider using [Node.js](https://nodejs.org/){target=\\_blank} 22.18+ and [npm](https://www.npmjs.com/){target=\\_blank} version 10.9.0+ to avoid issues with the plugin."} +{"page_id": "develop-smart-contracts-dev-environments-hardhat", "page_title": "Use Hardhat with Polkadot Hub", "index": 10, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 15302, "end_char": 16382, "estimated_token_count": 249, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\nHardhat provides a powerful environment for developing, testing, and deploying smart contracts on Polkadot Hub. Its plugin architecture allows seamless integration with PolkaVM through the `hardhat-resolc` and `hardhat-revive-node` plugins.\n\nExplore more about smart contracts through these resources:\n\n
\n\n- Guide __Smart Contracts on Polkadot__\n\n ---\n\n Dive into advanced smart contract concepts.\n\n [:octicons-arrow-right-24: Get Started](/develop/smart-contracts/)\n\n- External __Hardhat Documentation__\n\n ---\n\n Learn more about Hardhat's advanced features and best practices.\n\n [:octicons-arrow-right-24: Get Started](https://hardhat.org/docs){target=\\_blank}\n\n- External __OpenZeppelin Contracts__\n\n ---\n\n Test your skills by deploying contracts with prebuilt templates.\n\n [:octicons-arrow-right-24: Get Started](https://www.openzeppelin.com/solidity-contracts){target=\\_blank}\n\n
"} {"page_id": "develop-smart-contracts-dev-environments-remix", "page_title": "Use the Polkadot Remix IDE", "index": 0, "depth": 2, "title": "Overview", "anchor": "overview", "start_char": 1054, "end_char": 1367, "estimated_token_count": 67, "token_estimator": "heuristic-v1", "text": "## Overview\n\nRemix IDE is a robust browser-based development environment for smart contracts. This guide will walk you through the essentials of the [Polkadot Remix IDE](https://remix.polkadot.io/){target=\\_blank} to understand the processes of compiling, developing, and deploying smart contracts on Asset Hub."} {"page_id": "develop-smart-contracts-dev-environments-remix", "page_title": "Use the Polkadot Remix IDE", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 1367, "end_char": 1731, "estimated_token_count": 88, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore getting started, ensure you have:\n\n- A web browser with [Talisman](https://talisman.xyz/){target=\\_blank} extension installed.\n- Basic understanding of Solidity programming.\n- Some WND test tokens to cover transaction fees (easily obtainable from the [Polkadot faucet](https://faucet.polkadot.io/westend?parachain=1000){target=\\_blank})."} {"page_id": "develop-smart-contracts-dev-environments-remix", "page_title": "Use the Polkadot Remix IDE", "index": 2, "depth": 2, "title": "Accessing Remix IDE", "anchor": "accessing-remix-ide", "start_char": 1731, "end_char": 2141, "estimated_token_count": 106, "token_estimator": "heuristic-v1", "text": "## Accessing Remix IDE\n\nNavigate to [https://remix.polkadot.io/](https://remix.polkadot.io/){target=\\_blank}. The interface will load with a default workspace containing sample contracts.\n\n![](/images/develop/smart-contracts/evm-toolkit/dev-environments/remix/remix-1.webp)\n\nIn this interface, you can access a file explorer, edit your code, interact with various plugins for development, and use a terminal."}