Skip to content

Commit 2809bc3

Browse files
committed
add chain interactions overview
1 parent 6474683 commit 2809bc3

11 files changed

+5285
-6762
lines changed

.ai/categories/parachains.md

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

12571257
### Key Benefits
12581258

1259-
- **Unified Platform**: Deploys both PolkaVM-optimized and EVM-compatible contracts using a single pallet.
1259+
- **Unified platform**: Deploys both PolkaVM-optimized and EVM-compatible contracts using a single pallet.
12601260
- **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.
1261-
- **Ethereum Compatibility**: Supports full integration with Ethereum tooling via RPC adapter.
1261+
- **Ethereum compatibility**: Supports full integration with Ethereum tooling via RPC adapter.
12621262

12631263
### Implementation Examples
12641264

@@ -1276,7 +1276,7 @@ Frontier offers flexible integration depending on your compatibility needs:
12761276

12771277
For basic EVM support using Polkadot SDK native APIs:
12781278

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

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

@@ -1290,20 +1290,20 @@ For complete Ethereum ecosystem integration with Ethereum RPC support:
12901290

12911291
### Key Benefits
12921292

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

12981298
### Implementation Examples
12991299

13001300
Production implementations demonstrate Frontier's capabilities:
13011301

1302-
- **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}
1302+
- **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}.
13031303

13041304
## pallet-contracts (Legacy)
13051305

1306-
[`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.
1306+
[`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`.
13071307

13081308
### Implementation Example
13091309

.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/chain-interactions.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,95 @@
11
---
2+
title: Chain Interactions Overview
3+
description: Learn how to query data, send transactions, enable cross-chain communication, and manage accounts across the Polkadot ecosystem.
4+
categories: Chain Interactions
25
url: https://docs.polkadot.com/chain-interactions/
36
---
47

5-
TODO
8+
# Chain Interactions
9+
10+
## Introduction
11+
12+
Chain interactions form the foundation of building applications on Polkadot. Whether you're querying on-chain data, executing transactions, enabling cross-chain communication, or managing accounts, understanding how to interact with Polkadot-based chains is essential for application developers.
13+
14+
This section provides comprehensive guidance on the various ways to interact with Polkadot chains, from basic queries to complex cross-chain operations. You'll learn how to:
15+
16+
- Query on-chain state and subscribe to blockchain events
17+
- Send transactions and manage their lifecycle
18+
- Enable interoperability between parachains through XCM
19+
- Manage tokens and perform token operations
20+
- Create and manage accounts programmatically
21+
22+
Whether you're building a frontend application, a backend service, or integrating with the Polkadot ecosystem, these guides will equip you with the knowledge and tools to effectively interact with chains across the network.
23+
24+
## Core Interaction Patterns
25+
26+
### Query On-Chain Data
27+
28+
Accessing blockchain state is fundamental to building responsive applications. Polkadot provides multiple methods to query on-chain data, each suited for different use cases.
29+
30+
- **SDK Integration**: Use [Polkadot API (PAPI)](https://papi.how/){target=\_blank}, [Polkadot.js](https://polkadot.js.org/docs/){target=\_blank}, [Dedot](https://dedot.dev/){target=\_blank}, [PSI](https://github.com/paritytech/psi){target=\_blank}, or [Subxt](https://docs.rs/subxt/latest/subxt/){target=\_blank} to read blockchain state programmatically
31+
32+
- **REST API Access**: Query chain data through standardized REST endpoints for simpler integration
33+
34+
- **Runtime API Calls**: Execute runtime APIs directly for specialized queries and operations
35+
36+
Learn how to efficiently retrieve account balances, query storage, subscribe to events, and decode blockchain data in your applications.
37+
38+
### Send Transactions
39+
40+
Transactions are the primary mechanism for modifying blockchain state. Understanding transaction construction, signing, and submission is crucial for building interactive applications.
41+
42+
- **Transaction Construction**: Build transactions using various SDKs with proper encoding and formatting
43+
- **Fee Estimation**: Calculate transaction fees to ensure sufficient balance and optimize costs
44+
- **Multi-Token Fees**: Learn how to pay transaction fees with different tokens on supported chains
45+
46+
### Interoperability
47+
48+
Polkadot's true power lies in its native cross-chain capabilities. Through Cross-Consensus Messaging (XCM), chains can securely communicate and transfer assets across the ecosystem.
49+
50+
- **XCM Fundamentals**: Understand how to construct and send XCM messages between parachains using [ParaSpell XCM SDK](https://paraspell.github.io/docs/){target=\_blank} and [Polkadot API (PAPI)](https://papi.how/){target=\_blank}
51+
- **Asset Transfers**: Transfer tokens and other assets between different chains seamlessly
52+
- **Cross-Chain Communication**: Enable your applications to interact with multiple parachains
53+
- **Bridge Integration**: Connect to blockchains outside the Polkadot ecosystem using Snowbridge and other bridge solutions
54+
55+
Master the tools for estimating transfer costs, debugging XCM messages, and implementing robust cross-chain workflows.
56+
57+
### Token Operations
58+
59+
Polkadot Hub provides a unified platform for managing assets across the ecosystem. Understanding token operations is essential for DeFi applications and multi-chain asset management.
60+
61+
- **Asset Registration**: Learn how local and foreign assets are registered on the network
62+
- **Asset Hub Integration**: Interact with Polkadot's central asset management hub using [Polkadot.js Apps](https://polkadot.js.org/apps/){target=\_blank}
63+
- **Cross-Chain Assets**: Handle assets that exist across multiple parachains
64+
65+
### Accounts
66+
67+
Account management forms the basis of user identity and authentication in blockchain applications. Learn how to create, manage, and query accounts programmatically.
68+
69+
- **Account Creation**: Generate accounts using various SDKs in Rust, Python, and JavaScript
70+
- **Account Queries**: Retrieve account information including balances, nonces, and metadata
71+
72+
## Development Tools and SDKs
73+
74+
The Polkadot ecosystem offers a rich set of tools and libraries to facilitate chain interactions:
75+
76+
- **[Polkadot API (PAPI)](https://papi.how/){target=\_blank}**: Modern, type-safe TypeScript library with full metadata support
77+
- **[Polkadot.js](https://polkadot.js.org/docs/){target=\_blank}**: Comprehensive JavaScript library with extensive ecosystem support
78+
- **[Dedot](https://dedot.dev/){target=\_blank}**: Lightweight TypeScript library optimized for performance
79+
- **[PSI](https://github.com/paritytech/psi){target=\_blank}**: Polkadot Substrate Interface for streamlined development
80+
- **[Subxt](https://docs.rs/subxt/latest/subxt/){target=\_blank}**: Rust library for building robust substrate-based applications
81+
- **[Polkadot.js Apps](https://polkadot.js.org/apps/){target=\_blank}**: Web-based interface for exploring and interacting with chains
82+
83+
Each tool has its strengths, and choosing the right one depends on your project requirements, programming language preference, and specific use cases.
84+
85+
## Next Steps
86+
87+
Explore the sections below to dive deeper into specific chain interaction patterns:
88+
89+
- **[Query On-Chain Data](/chain-interactions/query-data/query-sdks/)**: Learn to read blockchain state efficiently
90+
- **[Send Transactions](/chain-interactions/send-transactions/with-sdks/)**: Master transaction construction and submission
91+
- **[Interoperability](/chain-interactions/send-transactions/interoperability/transfer-assets-parachains/)**: Enable cross-chain communication with XCM
92+
- **[Token Operations](/chain-interactions/token-operations/register-local-asset/)**: Manage assets across the Polkadot ecosystem
93+
- **[Accounts](/chain-interactions/accounts/create-account/)**: Create and query accounts programmatically
94+
95+
Each section provides practical examples, code snippets, and comprehensive guides to help you build production-ready applications on Polkadot.

0 commit comments

Comments
 (0)