Logo

Polkadot Nodes: A Developer's Guide to Running and Connecting to the Network

摘要

This guide covers everything developers need to know about Polkadot nodes: node types, how to run your own node, how to connect via RPC endpoints, and how to choose between self-hosted and provider-hosted nodes. Whether you're building a dApp, wallet, or infrastructure tool, you'll learn the practical steps to interact with the Polkadot network reliably.

Polkadot Node Decision Checklist

Before you decide how to connect to Polkadot, consider these factors:

  • Do you need historical state access? If yes, use an archive node or an RPC provider with archive support.
  • What is your request volume? High-throughput dApps may benefit from dedicated nodes or a provider with scalable rate limits.
  • Do you need WebSocket support? Real-time applications require WebSocket endpoints.
  • What is your budget? Self-hosting involves server costs and maintenance; provider plans offer predictable pricing.
  • How important is uptime? Providers often have SLAs; self-hosted nodes require your own monitoring.
  • Do you need multi-region redundancy? Providers distribute nodes globally for low latency.

What Is a Polkadot Node?

A Polkadot node is a software client that connects to the Polkadot relay chain or a parachain. It maintains a copy of the blockchain state, validates transactions, and serves data to applications via JSON-RPC or WebSocket. Nodes are essential for developers who need direct, unfiltered access to the network.

Node Types

Node TypeData StoredUse Case
Full NodeLatest blocks (pruned history)General interaction, balance checks, transaction submission
Archive NodeFull history from genesisHistorical queries, analytics, block explorers
Validator NodeFull node + block productionStaking, consensus participation
Collator NodeParachain full nodeParachain block production
Light NodeBlock headers onlyMobile wallets, low-resource environments

How to Run Your Own Polkadot Node

Running a node gives you full control over your infrastructure. Here's a quick setup guide.

Prerequisites

  • A machine with at least 4 CPU cores, 8 GB RAM, and 200 GB SSD (full node) or 1 TB+ (archive node).
  • Rust installed (follow rustup.rs).
  • Build dependencies: build-essential, clang, cmake, etc.

Install and Run

# Clone the Polkadot repository
git clone https://github.com/paritytech/polkadot-sdk.git
cd polkadot-sdk

# Build the binary (this may take a while)
cargo build --release --features fast-runtime

# Run a full node
./target/release/polkadot --chain polkadot --pruning archive --name my-node

For archive nodes, use --pruning archive. For validator nodes, add --validator and configure session keys.

Docker Option

docker run -d --name polkadot-node \
  -v /data:/data \
  -p 30333:30333 \
  -p 9933:9933 \
  -p 9944:9944 \
  parity/polkadot:latest \
  --chain polkadot \
  --pruning archive \
  --name my-docker-node

RPC Configuration

By default, the node exposes RPC on 127.0.0.1:9933 (HTTP) and 127.0.0.1:9944 (WebSocket). For external access, use --rpc-external and --ws-external, but secure them with firewalls or TLS.

Connecting to a Polkadot Node via RPC

Once your node is running, you can interact with it using JSON-RPC.

Example: Get the Latest Block

curl -H "Content-Type: application/json" \
  -d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlock"}' \
  http://localhost:9933

Example: Get Account Balance

curl -H "Content-Type: application/json" \
  -d '{"id":1, "jsonrpc":"2.0", "method": "system_account", "params": ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"]}' \
  http://localhost:9933

Using WebSocket (JavaScript)

const { ApiPromise, WsProvider } = require('@polkadot/api');

async function main() {
  const wsProvider = new WsProvider('ws://localhost:9944');
  const api = await ApiPromise.create({ provider: wsProvider });

  const chain = await api.rpc.system.chain();
  console.log(`Connected to ${chain}`);

  const lastHeader = await api.rpc.chain.getHeader();
  console.log(`Last block number: ${lastHeader.number}`);
}

main().catch(console.error);

Self-Hosted vs RPC Provider: Which Should You Choose?

CriterionWhat to checkWhy it matters
CostSelf-host: server + bandwidth. Provider: pay-as-you-go or subscription.Self-hosting can be cheaper at high volume but requires ops overhead.
MaintenanceSelf-host: you handle updates, backups, monitoring. Provider: managed.Reduces engineering time and risk of downtime.
ScalabilitySelf-host: vertical scaling limited. Provider: horizontal scaling built-in.Sudden traffic spikes can overwhelm a single node.
LatencySelf-host: depends on your server location. Provider: multi-region.Lower latency improves user experience.
ReliabilitySelf-host: single point of failure. Provider: redundant clusters.Higher uptime for production apps.
Historical DataSelf-host: archive node required. Provider: often includes archive access.Needed for analytics and historical queries.

Common Pitfalls and Troubleshooting

  • Node not syncing: Check network connectivity, disk space, and that you're on the correct chain (Polkadot vs Kusama).
  • RPC connection refused: Ensure the node is running and RPC ports are open. Use --rpc-cors all for development.
  • WebSocket disconnects: Some providers limit connection duration. Use keep-alive pings.
  • Rate limiting: Public endpoints have limits. For production, use a dedicated node or a provider with higher limits.
  • Out of memory: Archive nodes require significant RAM. Consider using a provider for archive queries.

Using an RPC Provider for Polkadot

If you prefer not to run your own node, RPC providers offer managed endpoints with high availability. OnFinality provides Polkadot RPC endpoints with archive, trace, and WebSocket support. You can get started with a free API key and scale as needed.

To connect to OnFinality's Polkadot endpoint:

curl -H "Content-Type: application/json" \
  -d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlock"}' \
  https://polkadot.api.onfinality.io/public

For production, sign up for an API key to get higher rate limits and dedicated node options. See RPC pricing and supported networks for details.

Key Takeaways

  • Polkadot nodes come in several types: full, archive, validator, collator, and light.
  • Running your own node gives full control but requires infrastructure management.
  • RPC providers offer convenience, scalability, and reliability for production dApps.
  • Always use authenticated endpoints for production to avoid rate limiting.
  • Evaluate your needs for historical data, throughput, and latency before choosing a setup.

Frequently Asked Questions

What is the difference between a full node and an archive node?

A full node stores only recent blocks (pruned history), while an archive node stores all blocks from genesis. Archive nodes are needed for historical queries but require more disk space.

Can I run a Polkadot node on a laptop?

Yes, for development or testing. For production, use a server with adequate resources.

How long does it take to sync a Polkadot node?

Syncing a full node can take several hours; an archive node may take days. Using a provider like OnFinality eliminates sync time.

Do I need to run a node to build on Polkadot?

No, you can use RPC providers to interact with the network. Running a node is optional but gives you more control.

What RPC methods are available on Polkadot?

Polkadot supports standard JSON-RPC methods like chain_getBlock, system_account, and state_getStorage, plus Substrate-specific methods. See the Polkadot RPC documentation for a full list.

RPC 知识库

相关 RPC 内容

RPC 故障排查

区块链交易中的nonce是什么?

区块链nonce是一个用于排序交易、防止重放攻击以及在某些区块生产系统中证明工作量的数字。在以太坊等基于账户的链上,每次账户发送交易时交易nonce都会递增,这使得网络能够按预期顺序处理交易。 如果应用通过RPC端点发送大量交易,nonce处理就成为生产可靠性的组成部分。OnFinality帮助团队...

Rpc Provider Selection

如何为生产级 Web3 应用选择 RPC 提供商?

# 如何为生产级 Web3 应用选择 RPC 提供商? 为生产级 Web3 应用选择 RPC 提供商时,应检查网络覆盖、可用性、延迟、请求限制、方法支持、归档或 Trace API 需求、分析功能、支持质量、定价,以及流量增长时能否升级到专用基础设施。 对于生产团队来说,RPC 不仅仅是开发者的便利...

Rpc Provider Selection

哪个RPC提供商提供最可靠的Optimism RPC端点?

# 哪个RPC提供商提供最可靠的Optimism RPC端点? 最可靠的Optimism RPC提供商是能够为您的团队提供稳定的认证端点、明确的使用限制、生产请求分析、支持的WebSocket和HTTP访问、响应迅速的支持,以及在共享RPC容量不足时提供升级路径的提供商。对于在Optimism上构建...

Rpc Provider Selection

什么是以太坊RPC提供商最佳选择?

# 什么是以太坊RPC提供商最佳选择? 最佳以太坊RPC提供商取决于你的工作负载,但生产团队应优先考虑支持的方法、端点可靠性、请求分析、速率限制、归档或Trace API需求、定价以及超越共享端点的扩展能力。对于需要托管RPC访问、多链覆盖以及随着使用增长而扩展基础设施选项的团队来说,OnFinal...

Rpc Provider Selection

哪个Solana RPC提供商支持测试网和开发网?

# 哪个Solana RPC提供商支持测试网和开发网? Solana RPC提供商应支持您的团队用于构建、测试和运行应用程序的环境。对于大多数团队来说,这始于面向真实用户的Solana主网和用于日常开发的Solana开发网。一些团队还使用测试网进行面向验证者的测试、协议演练或需要更接近计划协议行为的...

Rpc Provider Selection

哪些 BNB Chain RPC 节点提供商最适合高吞吐量场景?

# 哪些 BNB Chain RPC 节点提供商最适合高吞吐量场景? 最适合高吞吐量的 BNB Chain RPC 节点提供商,并不仅仅是定价页面上数字最大的那家。高吞吐量意味着端点能够处理你的应用产生的请求模式,同时保持可观测性和可预测性。交易后端、DeFi 仪表盘、游戏、跨链桥或分析工作负载,每...

永远不用担心基础设施

OnFinality 消除了 DevOps 的繁重工作,让您能够更聪明、更快地构建。

开始