Skip to content

Commit 8cc4255

Browse files
committed
add benchmark your pallet
1 parent 6474683 commit 8cc4255

13 files changed

+7394
-7717
lines changed

.ai/categories/parachains.md

Lines changed: 597 additions & 220 deletions
Large diffs are not rendered by default.

.ai/categories/smart-contracts.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10585,6 +10585,160 @@ Your local development environment is now active and accessible at `http://local
1058510585
You can connect wallets, deploy contracts using Remix or Hardhat, and interact with your smart contracts as you would on any Ethereum-compatible network.
1058610586

1058710587

10588+
---
10589+
10590+
Page Title: Migration FAQs and Considerations
10591+
10592+
- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-for-eth-devs-migration.md
10593+
- Canonical (HTML): https://docs.polkadot.com/smart-contracts/for-eth-devs/migration/
10594+
- Summary: Learn how to migrate your existing Ethereum contracts to the Polkadot Hub using REVM and PolkaVM by following these considerations.
10595+
10596+
# Migration FAQs and Considerations
10597+
10598+
## Introduction
10599+
10600+
This guide helps Ethereum developers migrate their smart contracts to Polkadot Hub. Most contracts work without modifications on the REVM backend, while the PolkaVM backend offers enhanced performance with minimal adaptation for standard patterns.
10601+
10602+
## Migration Considerations
10603+
10604+
Take into account the following considerations before migrating your contracts:
10605+
10606+
- Standard ERC-20, ERC-721, ERC-1155 tokens work without changes.
10607+
- DeFi protocols, DEXs, and AMMs migrate seamlessly.
10608+
- DAOs and governance contracts are fully compatible.
10609+
- Most Solidity contracts deploy identically to Ethereum.
10610+
10611+
## Migration Checklist
10612+
10613+
Before migrating your contracts, review this checklist:
10614+
10615+
- Factory contracts using PVM bytecode need pre-uploaded dependencies.
10616+
- Contracts using `EXTCODECOPY` for runtime manipulation require review (for projects that will use PVM bytecode, not EVM bytecode).
10617+
- Replace `transfer()` and `send()` with proper reentrancy guards (for projects that will use PVM bytecode, not EVM bytecode).
10618+
10619+
## Migration FAQs
10620+
10621+
### Which backend should I choose?
10622+
10623+
- Choose REVM if you want:
10624+
10625+
- Zero-modification deployment of existing Ethereum contracts.
10626+
- Exact EVM behavior for audited code.
10627+
- Compatibility with tools that inspect EVM bytecode.
10628+
- Rapid deployment without optimization.
10629+
10630+
- Choose PolkaVM if you want:
10631+
10632+
- Better performance for computation-heavy applications.
10633+
- Lower execution costs for intensive operations.
10634+
- Access to next-generation smart contract features.
10635+
10636+
If you are unsure which to choose, start with REVM for immediate compatibility, then consider PolkaVM for performance optimization once deployed.
10637+
10638+
### Do I need to rewrite my Solidity code?
10639+
10640+
No, for most contracts. Standard Solidity patterns work on both backends.
10641+
10642+
### What about factory contracts?
10643+
10644+
- **REVM**: Factory contracts work identically to Ethereum with no changes needed.
10645+
10646+
The original factory pattern is:
10647+
10648+
```solidity
10649+
contract TokenFactory {
10650+
function createToken(string memory name) public returns (address) {
10651+
// Creates new contract at runtime
10652+
Token newToken = new Token(name);
10653+
return address(newToken);
10654+
}
10655+
}
10656+
```
10657+
10658+
- **PolkaVM**: Factory contracts require pre-uploading dependent contracts.
10659+
10660+
Here's how to adapt the original factory pattern:
10661+
10662+
```solidity
10663+
contract TokenFactory {
10664+
// Reference pre-uploaded Token contract by hash
10665+
bytes32 public tokenCodeHash;
10666+
10667+
constructor(bytes32 _tokenCodeHash) {
10668+
tokenCodeHash = _tokenCodeHash;
10669+
}
10670+
10671+
function createToken(string memory name) public returns (address) {
10672+
// Instantiate from pre-uploaded code
10673+
Token newToken = new Token{salt: keccak256(abi.encode(name))}(name);
10674+
return address(newToken);
10675+
}
10676+
}
10677+
```
10678+
10679+
The deployment steps for PolkaVM factories are:
10680+
10681+
1. Upload the contract code to the chain.
10682+
2. Note the returned code hash.
10683+
3. Deploy the Factory contract with the contract code hash.
10684+
4. Factory can now instantiate contracts using the pre-uploaded code.
10685+
10686+
### How do gas costs compare?
10687+
10688+
For more information on gas costs, see the [Gas Model](/smart-contracts/for-eth-devs/gas-model/){target=\_blank} page.
10689+
10690+
### Which Solidity features are not supported?
10691+
10692+
For REVM, any Solidity feature will function smoothly without requiring changes or adaptations. For PVM, there are considerations, as was mentioned above.
10693+
10694+
For PolkaVM, there are some considerations:
10695+
10696+
- `EXTCODECOPY`: Only works in constructor code.
10697+
- Runtime code modification: Use on-chain constructors instead.
10698+
- **Gas stipends**: `address.send()` and `address.transfer()` don't provide reentrancy protection.
10699+
- **Unsupported operations**: `pc`, `extcodecopy`, `selfdestruct`, `blobhash`, and `blobbasefee` (blob-related operations).
10700+
10701+
### How do I handle the existential deposit?
10702+
10703+
Polkadot requires accounts to maintain a minimum balance (existential deposit or ED) to remain active.
10704+
10705+
This is handled automatically for you:
10706+
10707+
- Balance queries via Ethereum RPC automatically deduct the ED.
10708+
- New account transfers include ED in transaction fees.
10709+
- Contract-to-contract transfers draw ED from the transaction signer.
10710+
10711+
You typically don't need to do anything special, but be aware:
10712+
10713+
- Accounts below ED threshold are automatically deleted.
10714+
- ED is around 0.01 DOT (varies by network).
10715+
- Your contracts don't need to manage this explicitly.
10716+
10717+
### Can I use my existing development tools?
10718+
10719+
Yes. Both backends support:
10720+
10721+
- **Wallets**: [MetaMask](https://metamask.io/){target=\_blank}, [Talisman](https://talisman.xyz/){target=\_blank}, [SubWallet](https://www.subwallet.app/){target=\_blank}
10722+
- **Development frameworks**: [Hardhat](/smart-contracts/cookbook/smart-contracts/deploy-basic/hardhat/){target=\_blank}, [Foundry](/smart-contracts/cookbook/smart-contracts/deploy-basic/foundry/){target=\_blank}, [Remix](/smart-contracts/cookbook/smart-contracts/deploy-basic/remix/){target=\_blank} (just consider that for PVM bytecode, you will use the Polkadot version of the tooling)
10723+
- **Libraries**: [ethers.js](/smart-contracts/libraries/ethers-js/){target=\_blank}, [web3.js](/smart-contracts/libraries/web3-js/){target=\_blank}, [viem](/smart-contracts/libraries/viem/){target=\_blank}
10724+
- **Testing tools**: Your existing test suites work
10725+
10726+
Connect to Polkadot Hub's Ethereum JSON-RPC endpoint and use your familiar workflow.
10727+
10728+
## Conclusion
10729+
10730+
Most Ethereum contracts migrate to Polkadot Hub with minimal or no changes. Use REVM for seamless compatibility or PolkaVM for enhanced performance.
10731+
10732+
There are a few key points to keep in mind during migration:
10733+
10734+
- Replace `transfer()` and `send()` with `.call{value}("")` and use reentrancy guards (for projects that will use PVM bytecode, not EVM bytecode).
10735+
- PolkaVM factory contracts using PVM bytecode need pre-uploaded dependencies.
10736+
- Don't hardcode gas values.
10737+
- Test thoroughly on [TestNet](/smart-contracts/connect/#__tabbed_1_1){target=\_blank} before mainnet deployment.
10738+
10739+
Your existing Solidity knowledge and tooling transfer directly to Polkadot Hub, making migration straightforward for standard smart contract patterns.
10740+
10741+
1058810742
---
1058910743

1059010744
Page Title: Networks

.ai/categories/tooling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25913,7 +25913,7 @@ export default buildModule("StorageModule", (m) => {
2591325913
Deploy the contract to Polkadot Hub TestNet:
2591425914

2591525915
```bash
25916-
npx hardhat ignition deploy ./ignition/modules/Storage.ts --network polkadotHub
25916+
npx hardhat ignition deploy ./ignition/modules/Storage.ts --network polkadotTestNet
2591725917
```
2591825918

2591925919
You should see output similar to:

.ai/pages/parachains-customize-runtime-add-smart-contract-functionality.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ Any language that can compile to PolkaVM bytecode and utilize `pallet-revive`'s
5050

5151
### Key Benefits
5252

53-
- **Unified Platform**: Deploys both PolkaVM-optimized and EVM-compatible contracts using a single pallet.
53+
- **Unified platform**: Deploys both PolkaVM-optimized and EVM-compatible contracts using a single pallet.
5454
- **Performance**: PolkaVM execution provides improved performance compared to the traditional EVM, leveraging the [RISC-V](https://en.wikipedia.org/wiki/RISC-V){target=\_blank} architecture to map instructions to the CPU and requires little transpiling.
55-
- **Ethereum Compatibility**: Supports full integration with Ethereum tooling via RPC adapter.
55+
- **Ethereum compatibility**: Supports full integration with Ethereum tooling via RPC adapter.
5656

5757
### Implementation Examples
5858

@@ -70,7 +70,7 @@ Frontier offers flexible integration depending on your compatibility needs:
7070

7171
For basic EVM support using Polkadot SDK native APIs:
7272

73-
- **[`pallet-evm`](https://github.com/polkadot-evm/frontier/tree/master/frame/evm){target=\_blank}**: Provides the core EVM execution environment
73+
- **[`pallet-evm`](https://github.com/polkadot-evm/frontier/tree/master/frame/evm){target=\_blank}**: Provides the core EVM execution environment.
7474

7575
This configuration allows EVM contract execution but requires using Polkadot SDK-specific APIs for interaction.
7676

@@ -84,20 +84,20 @@ For complete Ethereum ecosystem integration with Ethereum RPC support:
8484

8585
### Key Benefits
8686

87-
- **Ethereum tooling compatibility**: Full compatibility with MetaMask, Hardhat, Remix, Truffle, and other Ethereum development tools
88-
- **Minimal-friction migration**: Deployment of existing Ethereum dApps with minimal or no modifications
89-
- **Native Ethereum formats**: Support for Ethereum transaction formats, signatures, and gas mechanics
90-
- **Block emulation**: Ethereum-style block structure within Substrate's block production
87+
- **Ethereum tooling compatibility**: Full compatibility with MetaMask, Hardhat, Remix, Foundry, and other Ethereum development tools.
88+
- **Minimal-friction migration**: Deployment of existing Ethereum dApps with minimal or no modifications.
89+
- **Native Ethereum formats**: Support for Ethereum transaction formats, signatures, and gas mechanics.
90+
- **Block emulation**: Ethereum-style block structure within Substrate's block production.
9191

9292
### Implementation Examples
9393

9494
Production implementations demonstrate Frontier's capabilities:
9595

96-
- **Moonbeam**: See their implementation of [`pallet-evm`](https://github.com/moonbeam-foundation/moonbeam/blob/9e2ddbc9ae8bf65f11701e7ccde50075e5fe2790/runtime/moonbeam/src/lib.rs#L532){target=\_blank} and [`pallet-ethereum`](https://github.com/moonbeam-foundation/moonbeam/blob/9e2ddbc9ae8bf65f11701e7ccde50075e5fe2790/runtime/moonbeam/src/lib.rs#L698){target=\_blank}
96+
- **Moonbeam**: See their implementation of [`pallet-evm`](https://github.com/moonbeam-foundation/moonbeam/blob/9e2ddbc9ae8bf65f11701e7ccde50075e5fe2790/runtime/moonbeam/src/lib.rs#L532){target=\_blank} and [`pallet-ethereum`](https://github.com/moonbeam-foundation/moonbeam/blob/9e2ddbc9ae8bf65f11701e7ccde50075e5fe2790/runtime/moonbeam/src/lib.rs#L698){target=\_blank}.
9797

9898
## pallet-contracts (Legacy)
9999

100-
[`pallet-contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank} is the original Wasm-based smart contract pallet for Polkadot SDK chains. While still functional, it's considered legacy as development efforts have shifted to pallet-revive.
100+
[`pallet-contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank} is the original Wasm-based smart contract pallet for Polkadot SDK chains. While still functional, it's considered legacy as development efforts have shifted to `pallet-revive`.
101101

102102
### Implementation Example
103103

0 commit comments

Comments
 (0)