Polkadot 开发实战:EVM 兼容环境搭建与账号体系解析

Polkadot开发实战:EVM兼容环境搭建与账号体系解析对于习惯了以太坊开发的Solidity工程师来说,进入Polkadot生态不仅是语言的迁移,更是对底层架构认知的更新。Polkadot通过Revive模块提供了对EVM的兼容支持,但这并不意味着完全照搬。本文将从最基

Polkadot 开发实战:EVM 兼容环境搭建与账号体系解析

对于习惯了以太坊开发的 Solidity 工程师来说,进入 Polkadot 生态不仅是语言的迁移,更是对底层架构认知的更新。Polkadot 通过 Revive 模块提供了对 EVM 的兼容支持,但这并不意味着完全照搬。

本文将从最基础的“克隆代码”开始,带你一步步完成 Polkadot SDK 的编译和 RPC 服务的启动,跑通本地测试节点。在实操之外,我们将重点探讨 Polkadot 独特的 SS58 账号体系、签名算法的区别,以及在 Revive 环境下计算 Gas 的三个关键维度。这是一份旨在解决“环境怎么搭”和“概念怎么懂”的实务笔记。

实操

Polkadot 上的 Solidity 与 EVM 开发者路径

克隆下载项目

git clone git@github.com:qiaopengjun5162/polkadot-sdk.git

切换到项目目录

cd polkadot-sdk/

编译 rpc 服务

cargo build --release -p pallet-revive-eth-rpc

实操

polkadot-sdk on  master [?] via 🦀 1.92.0 
➜ cargo build --release -p pallet-revive-eth-rpc                                                                                 
warning: unused import: `vec`
   --> substrate/frame/message-queue/src/lib.rs:208:13
    |
208 | use alloc::{vec, vec::Vec};
    |             ^^^
    |
    = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: `pallet-message-queue` (lib) generated 1 warning (run `cargo fix --lib -p pallet-message-queue` to apply 1 suggestion)
warning: unused import: `vec`
  --> polkadot/runtime/common/src/crowdloan/mod.rs:58:13
   |
58 | use alloc::{vec, vec::Vec};
   |             ^^^
   |
   = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: unused import: `vec`
  --> polkadot/runtime/common/src/paras_registrar/mod.rs:22:13
   |
22 | use alloc::{vec, vec::Vec};
   |             ^^^

warning: unused import: `vec`
  --> polkadot/runtime/common/src/slots/mod.rs:28:13
   |
28 | use alloc::{vec, vec::Vec};
   |             ^^^

warning: `polkadot-runtime-common` (lib) generated 3 warnings (run `cargo fix --lib -p polkadot-runtime-common` to apply 3 suggestions)
   Compiling libz-sys v1.1.12
warning: revive-dev-runtime@0.1.0: You are building WASM runtime using `wasm32-unknown-unknown` target, although Rust >= 1.84 supports `wasm32v1-none` target!
warning: revive-dev-runtime@0.1.0: You can install it with `rustup target add wasm32v1-none --toolchain stable-aarch64-apple-darwin` if you're using `rustup`.
warning: revive-dev-runtime@0.1.0: After installing `wasm32v1-none` target, you must rebuild WASM runtime from scratch, use `cargo clean` before building.
   Compiling libgit2-sys v0.18.0+1.9.0
   Compiling git2 v0.20.0
   Compiling pallet-revive-eth-rpc v0.1.0 (/Users/qiaopengjun/Code/Polkadot/polkadot-sdk/substrate/frame/revive/rpc)
    Finished `release` profile [optimized] target(s) in 32.26s

启动RPC服务

polkadot-sdk on  master [?] via 🦀 1.92.0 took 3.1s 
➜ target/release/eth-rpc       
2026-01-16 20:45:32 🌐 Connecting to node at: ws://127.0.0.1:9944 ...    
2026-01-16 20:45:32 🌟 Connected to node at: ws://127.0.0.1:9944    
2026-01-16 20:45:32 💾 Using in-memory database, keeping only 256 blocks in memory    
2026-01-16 20:45:32 Node does not have getAutomine RPC. Defaulting to automine=false. error: User(UserError { code: -32601, message: "Method not found", data: None })    
2026-01-16 20:45:32 〽️ Prometheus exporter started at 127.0.0.1:9616    
2026-01-16 20:45:32 Running JSON-RPC server: addr=127.0.0.1:8545,[::1]:8545    
2026-01-16 20:45:32 🔌 Subscribing to new blocks (BestBlocks)    
2026-01-16 20:45:32 🔌 Subscribing to new blocks (FinalizedBlocks)    

image-20260116205847441.png

编译Node节点服务


cargo build --release --bin substrate-node

## 实操
polkadot-sdk on  master [?] via 🦀 1.92.0 
➜ cargo build --release --bin substrate-node                                                                                       
warning: unused import: `vec`
   --> substrate/frame/message-queue/src/lib.rs:208:13
    |
208 | use alloc::{vec, vec::Vec};
    |             ^^^
    |
    = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: `pallet-message-queue` (lib) generated 1 warning (run `cargo fix --lib -p pallet-message-queue` to apply 1 suggestion)
warning: unused import: `vec`
  --> polkadot/runtime/common/src/crowdloan/mod.rs:58:13
   |
58 | use alloc::{vec, vec::Vec};
   |             ^^^
   |
   = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: unused import: `vec`
  --> polkadot/runtime/common/src/paras_registrar/mod.rs:22:13
   |
22 | use alloc::{vec, vec::Vec};
   |             ^^^

warning: unused import: `vec`
  --> polkadot/runtime/common/src/slots/mod.rs:28:13
   |
28 | use alloc::{vec, vec::Vec};
   |             ^^^

warning: `polkadot-runtime-common` (lib) generated 3 warnings (run `cargo fix --lib -p polkadot-runtime-common` to apply 3 suggestions)
warning: `pallet-message-queue` (lib) generated 1 warning (1 duplicate)
⚡ Found 4 strongly connected components which includes at least one cycle each
cycle(001) ∈ α: DisputeCoordinator ~~{"DisputeDistributionMessage"}~~> DisputeDistribution ~~{"DisputeCoordinatorMessage"}~~>  *
cycle(002) ∈ β: ApprovalVoting ~~{"ApprovalDistributionMessage"}~~> ApprovalDistribution ~~{"ApprovalVotingMessage"}~~>  *
cycle(003) ∈ γ: CandidateBacking ~~{"CollatorProtocolMessage"}~~> CollatorProtocol ~~{"CandidateBackingMessage"}~~>  *
cycle(004) ∈ δ: NetworkBridgeRx ~~{"GossipSupportMessage"}~~> GossipSupport ~~{"NetworkBridgeRxMessage"}~~>  *
⚡ Found 4 strongly connected components which includes at least one cycle each
cycle(001) ∈ α: DisputeCoordinator ~~{"DisputeDistributionMessage"}~~> DisputeDistribution ~~{"DisputeCoordinatorMessage"}~~>  *
cycle(002) ∈ β: ApprovalVoting ~~{"ApprovalDistributionMessage"}~~> ApprovalDistribution ~~{"ApprovalVotingMessage"}~~>  *
cycle(003) ∈ γ: CandidateBacking ~~{"CollatorProtocolMessage"}~~> CollatorProtocol ~~{"CandidateBackingMessage"}~~>  *
cycle(004) ∈ δ: NetworkBridgeRx ~~{"GossipSupportMessage"}~~> GossipSupport ~~{"NetworkBridgeRxMessage"}~~>  *
warning: frame-storage-access-test-runtime@0.1.0: You are building WASM runtime using `wasm32-unknown-unknown` target, although Rust >= 1.84 supports `wasm32v1-none` target!
warning: frame-storage-access-test-runtime@0.1.0: You can install it with `rustup target add wasm32v1-none --toolchain stable-aarch64-apple-darwin` if you're using `rustup`.
warning: frame-storage-access-test-runtime@0.1.0: After installing `wasm32v1-none` target, you must rebuild WASM runtime from scratch, use `cargo clean` before building.
warning: frame-storage-access-test-runtime@0.1.0: You are building WASM runtime using `wasm32-unknown-unknown` target, although Rust >= 1.84 supports `wasm32v1-none` target!
warning: frame-storage-access-test-runtime@0.1.0: You can install it with `rustup target add wasm32v1-none --toolchain stable-aarch64-apple-darwin` if you're using `rustup`.
warning: frame-storage-access-test-runtime@0.1.0: After installing `wasm32v1-none` target, you must rebuild WASM runtime from scratch, use `cargo clean` before building.
warning: unused import: `crate::log`
  --> substrate/frame/nomination-pools/src/migration.rs:19:5
   |
19 | use crate::log...

剩余50%的内容订阅专栏后可查看

点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论