You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .ai/categories/smart-contracts.md
+37-61Lines changed: 37 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10407,8 +10407,7 @@ Hardhat is a robust development environment for Ethereum-compatible chains that
10407
10407
10408
10408
Before getting started, ensure you have:
10409
10409
10410
-
- [Node.js](https://nodejs.org/){target=\_blank} (v16.0.0 or later) and npm installed.
10411
-
- Note: Use Node.js 22.5+ and npm version 10.9.0+ to avoid issues with the Polkadot plugin.
10410
+
- [Node.js](https://nodejs.org/){target=\_blank} (v22.5.0 or later) and npm installed.
10412
10411
- Basic understanding of Solidity programming.
10413
10412
- 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.
10414
10413
@@ -10430,7 +10429,7 @@ Before getting started, ensure you have:
10430
10429
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:
@@ -10462,14 +10461,11 @@ Before getting started, ensure you have:
10462
10461
10463
10462
## Compile Your Contract
10464
10463
10465
-
The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible. When compiling your contract, there are two ways to configure your compilation process:
10466
-
10467
-
- **npm compiler**: Uses library [@parity/resolc](https://www.npmjs.com/package/@parity/resolc){target=\_blank} for simplicity and ease of use.
10468
-
- **Binary compiler**: Uses your local `resolc` binary directly for more control and configuration options.
10464
+
The plugin will compile your Solidity contracts for Solidity versions `0.8.0` and higher to be PolkaVM compatible.
10469
10465
10470
10466
To compile your project, follow these instructions:
10471
10467
10472
-
1. Modify your Hardhat configuration file to specify which compilation process you will be using and activate the `polkavm` flag in the Hardhat network:
10468
+
1. Modify your Hardhat configuration file to specify which compilation process you will be using by specifying the `target` inside of the `polkadot` flag in the Hardhat network. By default it generates `pvm` bytecode, but you can use the EVM Backend by specifying `evm` as the `target`:
10473
10469
10474
10470
=== "npm Configuration"
10475
10471
@@ -10482,12 +10478,12 @@ To compile your project, follow these instructions:
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.
10522
10499
10523
-
The default settings used can be found in the [`constants.ts`](https://github.com/paritytech/hardhat-polkadot/blob/v0.1.5/packages/hardhat-polkadot-resolc/src/constants.ts#L8-L23){target=\_blank} file of the `hardhat-polkadot` source code. You can change them according to your project needs. Generally, the recommended settings for optimized outputs are the following:
10500
+
The default settings used can be found in the [`constants.ts`](https://github.com/paritytech/hardhat-polkadot/blob/v0.2.0-pre6/packages/hardhat-polkadot-resolc/src/constants.ts#L15-L30){target=\_blank} file of the `hardhat-polkadot` source code. You can change them according to your project needs. Generally, the recommended settings for optimized outputs are the following:
@@ -10532,35 +10509,34 @@ To compile your project, follow these instructions:
10532
10509
fallbackOz: true,
10533
10510
runs: 200,
10534
10511
},
10535
-
standardJson: true,
10536
10512
},
10537
10513
...
10538
10514
}
10539
10515
```
10540
10516
10541
-
You can check the [`ResolcConfig`](https://github.com/paritytech/hardhat-polkadot/blob/v0.1.5/packages/hardhat-polkadot-resolc/src/types.ts#L26){target=\_blank} for more information about compilation settings.
10517
+
You can check the [`ResolcConfig`](https://github.com/paritytech/hardhat-polkadot/blob/v0.2.0-pre6/packages/hardhat-polkadot-resolc/src/types.ts#L26){target=\_blank} for more information about compilation settings.
10542
10518
10543
10519
2. Compile the contract with Hardhat:
10544
10520
10545
10521
```bash
10546
10522
npx hardhat compile
10547
10523
```
10548
10524
10549
-
3. After successful compilation, you'll see the artifacts generated in the `artifacts-pvm` directory:
10525
+
3. After successful compilation, you'll see the artifacts generated in the `artifacts` directory:
10550
10526
10551
10527
```bash
10552
-
ls artifacts-pvm/contracts/*.sol/
10528
+
ls artifacts/contracts/*.sol/
10553
10529
```
10554
10530
10555
10531
You should see JSON files containing the contract ABI and bytecode of the contracts you compiled.
10556
10532
10557
10533
## Set Up a Testing Environment
10558
10534
10559
-
Hardhat allows you to spin up a local testing environment to test and validate your smart contract functionalities before deploying to live networks. The `hardhat-polkadot` plugin provides the possibility to spin up a local node with an ETH-RPC adapter for running local tests.
10535
+
Hardhat allows you to spin up a local testing environment to test and validate your smart contract functionalities before deploying to live networks. The `hardhat-polkadot` plugin provides the possibility to spin up a local `anvil-polkadot` node for running local tests or fork a live chain using the ETH-RPC adapter.
10560
10536
10561
-
For complete isolation and control over the testing environment, you can configure Hardhat to work with a fresh local Substrate node. This approach is ideal when you want to test in a clean environment without any existing state or when you need specific node configurations.
10537
+
For complete isolation and control over the testing environment, you can configure Hardhat to work with a fresh local `anvil-polkadot` node. This approach is ideal when you want to test in a clean environment without any existing state.
10562
10538
10563
-
Configure a local node setup by adding the node binary path along with the ETH-RPC adapter path:
10539
+
Configure a local node setup by adding the `anvil-polkadot` node binary path:
Replace `INSERT_PATH_TO_SUBSTRATE_NODE` and `INSERT_PATH_TO_ETH_RPC_ADAPTER` with the actual paths to your compiled binaries. The `dev: true` flag configures both the node and adapter for development mode. To obtain these binaries, check the [Installation](/develop/smart-contracts/local-development-node#install-the-substrate-node-and-eth-rpc-adapter){target=\_blank} section on the Local Development Node page.
10566
+
Replace `INSERT_PATH_TO_ANVIL_NODE` with the actual path to your binary. To obtain this binary, check the [Installation](/develop/smart-contracts/local-development-node#install-the-substrate-node-and-eth-rpc-adapter){target=\_blank} section on the Local Development Node page.
10591
10567
10592
10568
!!! warning
10593
10569
If you're using the default `hardhat.config.js` created by the `hardhat-polkadot` plugin, it includes a `forking` section pointing to the Polkadot Hub TestNet. When you run `npx hardhat node`, Hardhat will start a fork of that network. To use your local node instead, comment out the `forking` section; otherwise, `npx hardhat node` will continue to use the forked network even if a local node is defined in the configuration.
@@ -10598,7 +10574,7 @@ Once configured, start your chosen testing environment with:
10598
10574
npx hardhat node
10599
10575
```
10600
10576
10601
-
This command will launch either the forked network or local node (depending on your configuration) along with the ETH-RPC adapter, providing you with a complete testing environment ready for contract deployment and interaction. By default, the Substrate node will be running on `localhost:8000` and the ETH-RPC adapter on `localhost:8545`.
10577
+
This command will launch either the forked network along with the ETH-RPC adapter or the local `anvil-polkadot` node (depending on your configuration), providing you with a complete testing environment ready for contract deployment and interaction. By default, the `anvil-polkadot` node will be running on `localhost:8545`.
10602
10578
10603
10579
The output will be something like this:
10604
10580
@@ -10651,12 +10627,12 @@ Before deploying to a live network, you can deploy your contract to a local node
@@ -10740,7 +10716,7 @@ After testing your contract locally, you can deploy it to a live network. This g
10740
10716
10741
10717
Once deployed, you can create a script to interact with your contract. To do so, create a file called `scripts/interact.js` and add some logic to interact with the contract.
10742
10718
10743
-
For example, for the default `MyToken.sol` contract, you can use the following file that connects to the contract at its address and retrieves the `unlockTime`, which represents when funds can be withdrawn. The script converts this timestamp into a readable date and logs it. It then checks the contract's balance and displays it. Finally, it attempts to call the withdrawal function on the contract, but it catches and logs the error message if the withdrawal is not yet allowed (e.g., before `unlockTime`).
10719
+
For example, for the default `MyToken.sol` contract, you can use the following file that connects to the contract at its address and retrieves the token name and symbol. It then retrieves the `Total Supply`, which represents when funds can be withdrawn. Finally, it checks the deployer's balance and displays it.
0 commit comments