diff --git a/.ai/categories/smart-contracts.md b/.ai/categories/smart-contracts.md index 38ad40115..fea7f2990 100644 --- a/.ai/categories/smart-contracts.md +++ b/.ai/categories/smart-contracts.md @@ -10427,10 +10427,10 @@ Before getting started, ensure you have: npm init -y ``` -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: +3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts and to spawn a local node for testing: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@latest ``` 4. Create a Hardhat project: @@ -10439,7 +10439,7 @@ Before getting started, ensure you have: npx hardhat-polkadot init ``` - Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders: + Follow the project creation wizard. Your project will be created with three main folders: - **`contracts`**: Where your Solidity smart contracts live. - **`test`**: Contains your test files that validate contract functionality. @@ -10462,83 +10462,57 @@ 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: +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher. To compile your project, follow these instructions: -- **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. +1. Make sure your Hardhat configuration file looks like the following. Note that it may differ slightly based on the language choice made during the `init` step of setting up Hardhat: -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', + ```javascript title="hardhat.config.js" hl_lines="5-7 19-21 25-27" + module.exports = { + solidity: '0.8.28', + networks: { + hardhat: { + polkadot: { + target: 'evm', }, - networks: { - hardhat: { - polkavm: true, - }, + nodeConfig: { + nodeBinaryPath: './bin/dev-node', + rpcPort: 8000, + dev: 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', - }, + adapterConfig: { + adapterBinaryPath: './bin/eth-rpc', + dev: true, }, - networks: { - hardhat: { - polkavm: true, - }, + }, + localNode: { + polkadot: { + target: 'evm', }, - }; - ``` - - 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: - - ```javascript title="hardhat.config.js" hl_lines="4-10" - resolc: { - ... - settings: { - optimizer: { - enabled: true, - parameters: 'z', - fallbackOz: true, - runs: 200, + url: `http://127.0.0.1:8545`, + }, + polkadotHubTestnet: { + polkadot: { + target: 'evm', + }, + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + accounts: [vars.get('PRIVATE_KEY')], }, - 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. + To obtain the `dev-node` and `eth-rpc` binaries required in `nodeConfig` and `adapterConfig` respectively, check this [release](https://github.com/paritytech/hardhat-polkadot/releases/tag/nodes-19071579107){target=\_blank} and download the binaries as per your development platform and update the paths in your Hardhat config. + + !!! note + You might have to give executable permissions to the binaries: + ```bash + chmod +x /path/to/your/binary + ``` + In macOS environments, binaries are sometimes quarantined. To remove this, run: + ```bash + xattr -d com.apple.quarantine /path/to/your/binary + ``` 2. Compile the contract with Hardhat: @@ -10546,59 +10520,25 @@ 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. + You should see JSON files containing the contract ABIs and bytecodes for 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. - -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. - -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: +Hardhat lets you spin up a local testing environment to test and validate your smart contract functionality before deploying to live networks. The `hardhat-polkadot` plugin allows you to spin up a local node with an ETH-RPC adapter for running local tests. -```javascript title="hardhat.config.js" hl_lines="12-20" -// hardhat.config.js -require('@nomicfoundation/hardhat-toolbox'); - -require('@parity/hardhat-polkadot'); -/** @type import('hardhat/config').HardhatUserConfig */ -module.exports = { - ... - 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, - }, - }, - }, -}; -``` - -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. - -!!! 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. - -Once configured, start your chosen testing environment with: +Once you have set up the binaries as per the [Compile Your Contract](#compile-your-contract) section, start your local testing node with: ```bash 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 launches a local node with the ETH-RPC adapter, providing a complete testing environment ready for contract deployment and interaction. By default, the Substrate node runs on `localhost:8000`, and the ETH-RPC adapter on `localhost:8545`. The output will be something like this: @@ -10629,7 +10569,7 @@ When testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/net To run your test: -1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section. +1. Update the `hardhat.config.js` file as per the [Compile Your Contract](#compile-your-contract) section. 2. Execute the following command to run your tests: @@ -10641,27 +10581,15 @@ To run your test: Before deploying to a live network, you can deploy your contract to a local node using [Ignition](https://hardhat.org/ignition/docs/getting-started#overview){target=\_blank} modules: -1. Update the Hardhat configuration file to add the local network as a target for local deployment: - - ```javascript title="hardhat.config.js" hl_lines="13-16" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); +1. Make sure that the local network is added as a target in your Hardhat configuration file for local deployment: - require('@parity/hardhat-polkadot'); - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - ... - networks: { - hardhat: { - ... - }, - localNode: { - polkavm: true, - url: `http://127.0.0.1:8545`, - }, + ```javascript title="hardhat.config.js" + localNode: { + polkadot: { + target: 'evm', + }, + url: `http://127.0.0.1:8545`, }, - }, - }; ``` 2. Start a local node: @@ -10701,33 +10629,16 @@ After testing your contract locally, you can deploy it to a live network. This g npx hardhat vars get PRIVATE_KEY ``` -4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target: - - ```javascript title="hardhat.config.js" hl_lines="18-22" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); - - require('@parity/hardhat-polkadot'); - const { vars } = require('hardhat/config'); +4. Make sure the Polkadot Hub TestNet is added as a target in your Hardhat configuration file: - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - ... - networks: { - hardhat: { - ... - }, - localNode: { - ... - }, - polkadotHubTestnet: { - polkavm: true, - url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', - accounts: [vars.get('PRIVATE_KEY')], - }, + ```javascript title="hardhat.config.js" + polkadotHubTestnet: { + polkadot: { + target: 'evm', + }, + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + accounts: [vars.get('PRIVATE_KEY')], }, - }, - }; ``` 6. Deploy your contract using Ignition: diff --git a/.ai/categories/tooling.md b/.ai/categories/tooling.md index b81d713a2..eb974ecf5 100644 --- a/.ai/categories/tooling.md +++ b/.ai/categories/tooling.md @@ -19841,10 +19841,10 @@ Before getting started, ensure you have: npm init -y ``` -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: +3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts and to spawn a local node for testing: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@latest ``` 4. Create a Hardhat project: @@ -19853,7 +19853,7 @@ Before getting started, ensure you have: npx hardhat-polkadot init ``` - Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders: + Follow the project creation wizard. Your project will be created with three main folders: - **`contracts`**: Where your Solidity smart contracts live. - **`test`**: Contains your test files that validate contract functionality. @@ -19876,83 +19876,57 @@ 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: +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher. To compile your project, follow these instructions: -- **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. +1. Make sure your Hardhat configuration file looks like the following. Note that it may differ slightly based on the language choice made during the `init` step of setting up Hardhat: -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', + ```javascript title="hardhat.config.js" hl_lines="5-7 19-21 25-27" + module.exports = { + solidity: '0.8.28', + networks: { + hardhat: { + polkadot: { + target: 'evm', }, - networks: { - hardhat: { - polkavm: true, - }, + nodeConfig: { + nodeBinaryPath: './bin/dev-node', + rpcPort: 8000, + dev: 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', - }, + adapterConfig: { + adapterBinaryPath: './bin/eth-rpc', + dev: true, }, - networks: { - hardhat: { - polkavm: true, - }, + }, + localNode: { + polkadot: { + target: 'evm', }, - }; - ``` - - 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: - - ```javascript title="hardhat.config.js" hl_lines="4-10" - resolc: { - ... - settings: { - optimizer: { - enabled: true, - parameters: 'z', - fallbackOz: true, - runs: 200, + url: `http://127.0.0.1:8545`, + }, + polkadotHubTestnet: { + polkadot: { + target: 'evm', + }, + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + accounts: [vars.get('PRIVATE_KEY')], }, - 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. + To obtain the `dev-node` and `eth-rpc` binaries required in `nodeConfig` and `adapterConfig` respectively, check this [release](https://github.com/paritytech/hardhat-polkadot/releases/tag/nodes-19071579107){target=\_blank} and download the binaries as per your development platform and update the paths in your Hardhat config. + + !!! note + You might have to give executable permissions to the binaries: + ```bash + chmod +x /path/to/your/binary + ``` + In macOS environments, binaries are sometimes quarantined. To remove this, run: + ```bash + xattr -d com.apple.quarantine /path/to/your/binary + ``` 2. Compile the contract with Hardhat: @@ -19960,59 +19934,25 @@ 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. + You should see JSON files containing the contract ABIs and bytecodes for 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. - -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. - -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: - -```javascript title="hardhat.config.js" hl_lines="12-20" -// hardhat.config.js -require('@nomicfoundation/hardhat-toolbox'); - -require('@parity/hardhat-polkadot'); -/** @type import('hardhat/config').HardhatUserConfig */ -module.exports = { - ... - 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, - }, - }, - }, -}; -``` - -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. - -!!! 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. +Hardhat lets you spin up a local testing environment to test and validate your smart contract functionality before deploying to live networks. The `hardhat-polkadot` plugin allows you to spin up a local node with an ETH-RPC adapter for running local tests. -Once configured, start your chosen testing environment with: +Once you have set up the binaries as per the [Compile Your Contract](#compile-your-contract) section, start your local testing node with: ```bash 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 launches a local node with the ETH-RPC adapter, providing a complete testing environment ready for contract deployment and interaction. By default, the Substrate node runs on `localhost:8000`, and the ETH-RPC adapter on `localhost:8545`. The output will be something like this: @@ -20043,7 +19983,7 @@ When testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/net To run your test: -1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section. +1. Update the `hardhat.config.js` file as per the [Compile Your Contract](#compile-your-contract) section. 2. Execute the following command to run your tests: @@ -20055,27 +19995,15 @@ To run your test: Before deploying to a live network, you can deploy your contract to a local node using [Ignition](https://hardhat.org/ignition/docs/getting-started#overview){target=\_blank} modules: -1. Update the Hardhat configuration file to add the local network as a target for local deployment: - - ```javascript title="hardhat.config.js" hl_lines="13-16" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); +1. Make sure that the local network is added as a target in your Hardhat configuration file for local deployment: - require('@parity/hardhat-polkadot'); - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - ... - networks: { - hardhat: { - ... - }, - localNode: { - polkavm: true, - url: `http://127.0.0.1:8545`, - }, + ```javascript title="hardhat.config.js" + localNode: { + polkadot: { + target: 'evm', + }, + url: `http://127.0.0.1:8545`, }, - }, - }; ``` 2. Start a local node: @@ -20115,33 +20043,16 @@ After testing your contract locally, you can deploy it to a live network. This g npx hardhat vars get PRIVATE_KEY ``` -4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target: - - ```javascript title="hardhat.config.js" hl_lines="18-22" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); +4. Make sure the Polkadot Hub TestNet is added as a target in your Hardhat configuration file: - require('@parity/hardhat-polkadot'); - const { vars } = require('hardhat/config'); - - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - ... - networks: { - hardhat: { - ... - }, - localNode: { - ... - }, - polkadotHubTestnet: { - polkavm: true, - url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', - accounts: [vars.get('PRIVATE_KEY')], - }, + ```javascript title="hardhat.config.js" + polkadotHubTestnet: { + polkadot: { + target: 'evm', + }, + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + accounts: [vars.get('PRIVATE_KEY')], }, - }, - }; ``` 6. Deploy your contract using Ignition: diff --git a/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md b/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md index 9f7297b89..51fb74d1b 100644 --- a/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md +++ b/.ai/pages/develop-smart-contracts-dev-environments-hardhat.md @@ -54,10 +54,10 @@ Before getting started, ensure you have: npm init -y ``` -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: +3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts and to spawn a local node for testing: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@latest ``` 4. Create a Hardhat project: @@ -66,7 +66,7 @@ Before getting started, ensure you have: npx hardhat-polkadot init ``` - Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders: + Follow the project creation wizard. Your project will be created with three main folders: - **`contracts`**: Where your Solidity smart contracts live. - **`test`**: Contains your test files that validate contract functionality. @@ -89,83 +89,57 @@ 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: +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher. To compile your project, follow these instructions: -- **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. +1. Make sure your Hardhat configuration file looks like the following. Note that it may differ slightly based on the language choice made during the `init` step of setting up Hardhat: -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', + ```javascript title="hardhat.config.js" hl_lines="5-7 19-21 25-27" + module.exports = { + solidity: '0.8.28', + networks: { + hardhat: { + polkadot: { + target: 'evm', }, - networks: { - hardhat: { - polkavm: true, - }, + nodeConfig: { + nodeBinaryPath: './bin/dev-node', + rpcPort: 8000, + dev: 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', - }, + adapterConfig: { + adapterBinaryPath: './bin/eth-rpc', + dev: true, }, - networks: { - hardhat: { - polkavm: true, - }, + }, + localNode: { + polkadot: { + target: 'evm', }, - }; - ``` - - 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: - - ```javascript title="hardhat.config.js" hl_lines="4-10" - resolc: { - ... - settings: { - optimizer: { - enabled: true, - parameters: 'z', - fallbackOz: true, - runs: 200, + url: `http://127.0.0.1:8545`, + }, + polkadotHubTestnet: { + polkadot: { + target: 'evm', + }, + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + accounts: [vars.get('PRIVATE_KEY')], }, - 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. + To obtain the `dev-node` and `eth-rpc` binaries required in `nodeConfig` and `adapterConfig` respectively, check this [release](https://github.com/paritytech/hardhat-polkadot/releases/tag/nodes-19071579107){target=\_blank} and download the binaries as per your development platform and update the paths in your Hardhat config. + + !!! note + You might have to give executable permissions to the binaries: + ```bash + chmod +x /path/to/your/binary + ``` + In macOS environments, binaries are sometimes quarantined. To remove this, run: + ```bash + xattr -d com.apple.quarantine /path/to/your/binary + ``` 2. Compile the contract with Hardhat: @@ -173,59 +147,25 @@ 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. + You should see JSON files containing the contract ABIs and bytecodes for 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. - -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. - -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: - -```javascript title="hardhat.config.js" hl_lines="12-20" -// hardhat.config.js -require('@nomicfoundation/hardhat-toolbox'); +Hardhat lets you spin up a local testing environment to test and validate your smart contract functionality before deploying to live networks. The `hardhat-polkadot` plugin allows you to spin up a local node with an ETH-RPC adapter for running local tests. -require('@parity/hardhat-polkadot'); -/** @type import('hardhat/config').HardhatUserConfig */ -module.exports = { - ... - 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, - }, - }, - }, -}; -``` - -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. - -!!! 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. - -Once configured, start your chosen testing environment with: +Once you have set up the binaries as per the [Compile Your Contract](#compile-your-contract) section, start your local testing node with: ```bash 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 launches a local node with the ETH-RPC adapter, providing a complete testing environment ready for contract deployment and interaction. By default, the Substrate node runs on `localhost:8000`, and the ETH-RPC adapter on `localhost:8545`. The output will be something like this: @@ -256,7 +196,7 @@ When testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/net To run your test: -1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section. +1. Update the `hardhat.config.js` file as per the [Compile Your Contract](#compile-your-contract) section. 2. Execute the following command to run your tests: @@ -268,27 +208,15 @@ To run your test: Before deploying to a live network, you can deploy your contract to a local node using [Ignition](https://hardhat.org/ignition/docs/getting-started#overview){target=\_blank} modules: -1. Update the Hardhat configuration file to add the local network as a target for local deployment: - - ```javascript title="hardhat.config.js" hl_lines="13-16" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); +1. Make sure that the local network is added as a target in your Hardhat configuration file for local deployment: - require('@parity/hardhat-polkadot'); - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - ... - networks: { - hardhat: { - ... - }, - localNode: { - polkavm: true, - url: `http://127.0.0.1:8545`, - }, + ```javascript title="hardhat.config.js" + localNode: { + polkadot: { + target: 'evm', + }, + url: `http://127.0.0.1:8545`, }, - }, - }; ``` 2. Start a local node: @@ -328,33 +256,16 @@ After testing your contract locally, you can deploy it to a live network. This g npx hardhat vars get PRIVATE_KEY ``` -4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target: - - ```javascript title="hardhat.config.js" hl_lines="18-22" - // hardhat.config.js - require('@nomicfoundation/hardhat-toolbox'); +4. Make sure the Polkadot Hub TestNet is added as a target in your Hardhat configuration file: - require('@parity/hardhat-polkadot'); - const { vars } = require('hardhat/config'); - - /** @type import('hardhat/config').HardhatUserConfig */ - module.exports = { - ... - networks: { - hardhat: { - ... - }, - localNode: { - ... - }, - polkadotHubTestnet: { - polkavm: true, - url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', - accounts: [vars.get('PRIVATE_KEY')], - }, + ```javascript title="hardhat.config.js" + polkadotHubTestnet: { + polkadot: { + target: 'evm', + }, + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + accounts: [vars.get('PRIVATE_KEY')], }, - }, - }; ``` 6. Deploy your contract using Ignition: diff --git a/.ai/site-index.json b/.ai/site-index.json index 669b7f7f5..472e4e9b8 100644 --- a/.ai/site-index.json +++ b/.ai/site-index.json @@ -2720,12 +2720,12 @@ } ], "stats": { - "chars": 18520, - "words": 2475, + "chars": 14590, + "words": 2051, "headings": 11, - "estimated_token_count_total": 4188 + "estimated_token_count_total": 3341 }, - "hash": "sha256:fe008393aa37c27bb71b4483d4e2c4fbcda94f8c1be461fdd07eff40efbb4e26", + "hash": "sha256:8faa740768edb9c21e8738c8fd395f37430fa01888b86042ba43eb87d29560ff", "token_estimator": "heuristic-v1" }, { 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..b93ae4b9b 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,28 +6,31 @@ 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', + nodeBinaryPath: './bin/dev-node', rpcPort: 8000, dev: true, }, adapterConfig: { - adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER', + adapterBinaryPath: './bin/eth-rpc', dev: true, }, }, localNode: { - polkavm: true, + polkadot: { + target: 'evm', + }, url: `http://127.0.0.1:8545`, }, polkadotHubTestnet: { - polkavm: true, + polkadot: { + target: 'evm', + }, url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', accounts: [vars.get('PRIVATE_KEY')], }, diff --git a/develop/smart-contracts/dev-environments/hardhat.md b/develop/smart-contracts/dev-environments/hardhat.md index bb407c951..338174b7e 100644 --- a/develop/smart-contracts/dev-environments/hardhat.md +++ b/develop/smart-contracts/dev-environments/hardhat.md @@ -50,10 +50,10 @@ Before getting started, ensure you have: npm init -y ``` -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: +3. To interact with Polkadot, Hardhat requires the following plugin to compile contracts and to spawn a local node for testing: ```bash - npm install --save-dev @parity/hardhat-polkadot@0.1.9 + npm install --save-dev @parity/hardhat-polkadot@latest ``` 4. Create a Hardhat project: @@ -62,7 +62,7 @@ Before getting started, ensure you have: npx hardhat-polkadot init ``` - Select **Create a JavaScript project** when prompted and follow the instructions. After that, your project will be created with three main folders: + Follow the project creation wizard. Your project will be created with three main folders: - **`contracts`**: Where your Solidity smart contracts live. - **`test`**: Contains your test files that validate contract functionality. @@ -85,94 +85,51 @@ 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: +The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher. To compile your project, follow these instructions: -- **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. +1. Make sure your Hardhat configuration file looks like the following. Note that it may differ slightly based on the language choice made during the `init` step of setting up Hardhat: -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: + ```javascript title="hardhat.config.js" hl_lines="5-7 19-21 25-27" + --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:7:' + ``` - === "npm Configuration" + To obtain the `dev-node` and `eth-rpc` binaries required in `nodeConfig` and `adapterConfig` respectively, check this [release](https://github.com/paritytech/hardhat-polkadot/releases/tag/nodes-19071579107){target=\_blank} and download the binaries as per your development platform and update the paths in your Hardhat config. - ```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' + !!! note + You might have to give executable permissions to the binaries: + ```bash + chmod +x /path/to/your/binary ``` - - === "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' + In macOS environments, binaries are sometimes quarantined. To remove this, run: + ```bash + xattr -d com.apple.quarantine /path/to/your/binary ``` - 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: - - ```javascript title="hardhat.config.js" hl_lines="4-10" - resolc: { - ... - settings: { - optimizer: { - enabled: true, - parameters: 'z', - 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. - 2. Compile the contract with Hardhat: ```bash 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. + You should see JSON files containing the contract ABIs and bytecodes for 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. - -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. +Hardhat lets you spin up a local testing environment to test and validate your smart contract functionality before deploying to live networks. The `hardhat-polkadot` plugin allows you to spin up a local node with an ETH-RPC adapter for running local tests. -Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path: - -```javascript title="hardhat.config.js" hl_lines="12-20" ---8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4' - ---8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:6:7' - ... - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:12:24' ---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. - -!!! 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. - -Once configured, start your chosen testing environment with: +Once you have set up the binaries as per the [Compile Your Contract](#compile-your-contract) section, start your local testing node with: ```bash 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 launches a local node with the ETH-RPC adapter, providing a complete testing environment ready for contract deployment and interaction. By default, the Substrate node runs on `localhost:8000`, and the ETH-RPC adapter on `localhost:8545`. The output will be something like this: @@ -184,7 +141,7 @@ When testing your contract, be aware that [`@nomicfoundation/hardhat-toolbox/net To run your test: -1. Update the `hardhat.config.js` file accordingly to the [Set Up a Testing Environment](#set-up-a-testing-environment) section. +1. Update the `hardhat.config.js` file as per the [Compile Your Contract](#compile-your-contract) section. 2. Execute the following command to run your tests: @@ -196,17 +153,10 @@ To run your test: Before deploying to a live network, you can deploy your contract to a local node using [Ignition](https://hardhat.org/ignition/docs/getting-started#overview){target=\_blank} modules: -1. Update the Hardhat configuration file to add the local network as a target for local deployment: - - ```javascript title="hardhat.config.js" hl_lines="13-16" - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4' +1. Make sure that the local network is added as a target in your Hardhat configuration file for local deployment: - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:6:7' - ... - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:12:13' - ... - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:24:28' - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:33:35' + ```javascript title="hardhat.config.js" + --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:24:29' ``` 2. Start a local node: @@ -246,22 +196,10 @@ After testing your contract locally, you can deploy it to a live network. This g npx hardhat vars get PRIVATE_KEY ``` -4. Update your Hardhat configuration file with network settings for the Polkadot network you want to target: - - ```javascript title="hardhat.config.js" hl_lines="18-22" - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:1:4' - - const { vars } = require('hardhat/config'); +4. Make sure the Polkadot Hub TestNet is added as a target in your Hardhat configuration file: - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:6:7' - ... - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:12:13' - ... - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:24:24' - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:25:25' - ... - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:28:33' - --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:33:35' + ```javascript title="hardhat.config.js" + --8<-- 'code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js:30:36' ``` 6. Deploy your contract using Ignition: diff --git a/llms-full.jsonl b/llms-full.jsonl index d55a9aacf..b4fa83279 100644 --- a/llms-full.jsonl +++ b/llms-full.jsonl @@ -314,15 +314,15 @@ {"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": 2, "depth": 2, "title": "Set Up Hardhat", "anchor": "set-up-hardhat", "start_char": 1862, "end_char": 3190, "estimated_token_count": 296, "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 and to spawn a local node for testing:\n\n ```bash\n npm install --save-dev @parity/hardhat-polkadot@latest\n ```\n\n4. Create a Hardhat project:\n\n ```bash\n npx hardhat-polkadot init\n ```\n\n Follow the project creation wizard. 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": 3190, "end_char": 5396, "estimated_token_count": 488, "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 compile your project, follow these instructions:\n\n1. Make sure your Hardhat configuration file looks like the following. Note that it may differ slightly based on the language choice made during the `init` step of setting up Hardhat:\n\n ```javascript title=\"hardhat.config.js\" hl_lines=\"5-7 19-21 25-27\"\n module.exports = {\n solidity: '0.8.28',\n networks: {\n hardhat: {\n polkadot: {\n target: 'evm',\n },\n nodeConfig: {\n nodeBinaryPath: './bin/dev-node',\n rpcPort: 8000,\n dev: true,\n },\n adapterConfig: {\n adapterBinaryPath: './bin/eth-rpc',\n dev: true,\n },\n },\n localNode: {\n polkadot: {\n target: 'evm',\n },\n url: `http://127.0.0.1:8545`,\n },\n polkadotHubTestnet: {\n polkadot: {\n target: 'evm',\n },\n url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',\n accounts: [vars.get('PRIVATE_KEY')],\n },\n },\n };\n\n ```\n\n To obtain the `dev-node` and `eth-rpc` binaries required in `nodeConfig` and `adapterConfig` respectively, check this [release](https://github.com/paritytech/hardhat-polkadot/releases/tag/nodes-19071579107){target=\\_blank} and download the binaries as per your development platform and update the paths in your Hardhat config. \n\n !!! note\n You might have to give executable permissions to the binaries:\n ```bash\n chmod +x /path/to/your/binary\n ```\n In macOS environments, binaries are sometimes quarantined. To remove this, run:\n ```bash\n xattr -d com.apple.quarantine /path/to/your/binary\n ```\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 ABIs and bytecodes for 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": 5396, "end_char": 7574, "estimated_token_count": 686, "token_estimator": "heuristic-v1", "text": "## Set Up a Testing Environment\n\nHardhat lets you spin up a local testing environment to test and validate your smart contract functionality before deploying to live networks. The `hardhat-polkadot` plugin allows you to spin up a local node with an ETH-RPC adapter for running local tests.\n\nOnce you have set up the binaries as per the [Compile Your Contract](#compile-your-contract) section, start your local testing node with:\n\n```bash\nnpx hardhat node\n```\n\nThis command launches a local node with the ETH-RPC adapter, providing a complete testing environment ready for contract deployment and interaction. By default, the Substrate node runs 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": 7574, "end_char": 8451, "estimated_token_count": 218, "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 as per the [Compile Your Contract](#compile-your-contract) 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": 8451, "end_char": 9283, "estimated_token_count": 197, "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. Make sure that the local network is added as a target in your Hardhat configuration file for local deployment:\n\n ```javascript title=\"hardhat.config.js\"\n localNode: {\n polkadot: {\n target: 'evm',\n },\n url: `http://127.0.0.1:8545`,\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": 9283, "end_char": 11050, "estimated_token_count": 394, "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. Make sure the Polkadot Hub TestNet is added as a target in your Hardhat configuration file:\n\n ```javascript title=\"hardhat.config.js\"\n polkadotHubTestnet: {\n polkadot: {\n target: 'evm',\n },\n url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',\n accounts: [vars.get('PRIVATE_KEY')],\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": 11050, "end_char": 12850, "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": 12850, "end_char": 13510, "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": 13510, "end_char": 14590, "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."}