Logo

Polkadot RPC: A Complete Guide to Endpoints, Methods, and Providers

Key Takeaways

  • Polkadot RPC endpoints are available for the relay chain, parachains like Asset Hub, and optionally via Ethereum JSON-RPC compatibility.
  • The Polkadot JSON-RPC API includes methods for chain state, extrinsics, and runtime calls, documented in the polkadot.js library.
  • Choosing a reliable RPC provider is critical for production dApps; factors include uptime, latency, scalability, and support for archive data.
  • OnFinality offers managed Polkadot RPC endpoints and dedicated nodes with global infrastructure for low-latency access.
  • Developers should test RPC endpoints for performance and reliability before integrating into production applications.
  • Polkadot's shared security model means RPC nodes can serve both relay chain and parachain data, but each chain has its own endpoint.
  • For high-throughput applications, dedicated nodes provide guaranteed resources and avoid rate limiting common with shared endpoints.

Understanding Polkadot RPC Architecture

Polkadot is a heterogeneous multi-chain network consisting of a central relay chain and multiple parachains. Each parachain runs its own runtime and maintains its own state, which means each chain exposes its own RPC endpoint. The relay chain provides shared security and cross-chain messaging via XCM (Cross-Consensus Messaging).

RPC endpoints for Polkadot are typically available in two formats: WebSocket (WSS) and HTTP. The standard Polkadot JSON-RPC API uses WebSocket for subscriptions and HTTP for request-response. Additionally, Polkadot Hub (the system parachain for smart contracts) supports Ethereum JSON-RPC compatibility, allowing developers to use MetaMask and other Ethereum tools.

  • Relay chain RPC: Provides access to core Polkadot functionality like staking, governance, and validator queries.
  • Parachain RPC: Each parachain (e.g., Asset Hub, Bridge Hub) has its own RPC endpoint for chain-specific operations.
  • Ethereum JSON-RPC: Available on Polkadot Hub for EVM compatibility, enabling Solidity smart contracts and Ethereum tooling.
  • Substrate API Sidecar: A RESTful API that provides higher-level abstractions over the raw RPC, useful for indexing and historical data.

Key Polkadot JSON-RPC Methods

The Polkadot JSON-RPC API is organized by namespaces corresponding to Substrate pallets. The most commonly used namespaces include `chain`, `state`, `system`, `author`, and `payment`. Each namespace exposes methods for querying chain data, submitting transactions, and interacting with runtime modules.

For developers using polkadot.js, the RPC methods are accessible via `api.rpc.<namespace>.<method>()`. The official polkadot.js documentation provides a comprehensive list of available methods, which may vary depending on node configuration and enabled pallets.

  • `chain.getBlock()`: Retrieve a block by hash or number.
  • `state.getStorage()`: Query storage values for a given key.
  • `system.chain()`: Get the chain name (e.g., 'Polkadot').
  • `author.submitExtrinsic()`: Submit a signed extrinsic to the transaction pool.
  • `payment.queryInfo()`: Estimate the fee for a given extrinsic.
  • `rpc.methods()`: List all available RPC methods on the node.

Connecting to Polkadot Networks

Developers can connect to Polkadot mainnet, testnets (like Paseo), and parachains using the appropriate RPC endpoints. For production applications, it is essential to use reliable, low-latency endpoints that can handle high request volumes. Public endpoints may have rate limits or be unreliable for production use.

When connecting to Polkadot Hub for smart contract development, you can use either the native Substrate RPC (WSS) or the Ethereum JSON-RPC (HTTP). The Ethereum-compatible endpoint allows you to use familiar tools like Hardhat, Foundry, and ethers.js.

  • Mainnet: wss://rpc.polkadot.io (official), or use managed providers like OnFinality.
  • Testnet (Paseo): wss://paseo-rpc.dwellir.com, or OnFinality's testnet endpoints.
  • Polkadot Hub (Ethereum RPC): https://eth-rpc.polkadot.io (mainnet), https://eth-rpc-testnet.polkadot.io (testnet).
  • Always verify endpoint URLs from official sources or trusted providers to avoid phishing or outdated nodes.

Choosing a Polkadot RPC Provider

Selecting the right RPC provider is crucial for dApp performance and reliability. Key factors include uptime guarantees, geographic distribution, support for archive nodes, and pricing model. Shared public endpoints are suitable for development, but production applications often require dedicated nodes or premium API services.

OnFinality offers managed Polkadot RPC endpoints with global infrastructure, automatic failover, and support for both shared and dedicated node options. Their service is designed for developers who need consistent performance without the overhead of node management.

  • Uptime and reliability: Look for providers with SLA-backed uptime and redundant infrastructure.
  • Latency: Geographically distributed endpoints reduce latency for global user bases.
  • Archive data: Some applications require full historical state; ensure the provider supports archive nodes.
  • Rate limits: Understand the request limits for shared plans and whether dedicated nodes are available.
  • Ethereum compatibility: If building on Polkadot Hub, ensure the provider supports Ethereum JSON-RPC endpoints.

Best Practices for Using Polkadot RPC

To build robust applications on Polkadot, follow these best practices when interacting with RPC endpoints. Always handle connection errors gracefully, implement retry logic with exponential backoff, and use WebSocket subscriptions for real-time updates instead of polling.

For high-throughput applications, consider using dedicated nodes to avoid rate limiting and ensure consistent performance. Additionally, cache frequently accessed data (like chain metadata or account balances) to reduce RPC calls.

  • Use WebSocket for event-driven updates (e.g., new blocks, transaction status changes).
  • Batch requests when possible to reduce overhead and improve efficiency.
  • Monitor endpoint health and switch to backup endpoints on failure.
  • Validate RPC responses and handle edge cases like chain reorganizations.
  • For production, use a managed provider with built-in redundancy and monitoring.

Troubleshooting Common Polkadot RPC Issues

Developers may encounter issues such as connection timeouts, stale data, or unsupported methods. These often stem from using outdated endpoints, misconfigured nodes, or network congestion. The first step is to verify the endpoint URL and ensure it matches the intended network.

If you experience high latency or frequent disconnections, consider switching to a provider with better geographic coverage or upgrading to a dedicated node. For method-specific errors, consult the polkadot.js documentation to confirm the method is available on your target node.

  • Connection refused: Check firewall settings and ensure the endpoint is correct.
  • Method not found: The node may not have the required pallet enabled; try a different provider.
  • Stale data: Ensure you are connected to a fully synced node; archive nodes are best for historical queries.
  • Rate limiting: Upgrade to a paid plan or dedicated node to increase request limits.

Polkadot RPC vs. Other Blockchain RPCs

Polkadot's RPC differs from Ethereum's in several ways due to its Substrate-based architecture. While Ethereum uses a single JSON-RPC specification, Polkadot's RPC methods are generated from runtime metadata, meaning they can change with runtime upgrades. This dynamic nature requires developers to use libraries like polkadot.js that handle metadata parsing automatically.

Additionally, Polkadot's multi-chain nature means you often need to interact with multiple RPC endpoints for a single application (e.g., relay chain for staking, Asset Hub for token transfers). This complexity makes a unified API provider like OnFinality valuable, as it simplifies endpoint management.

  • Dynamic methods: RPC methods are defined by runtime metadata, not a static spec.
  • Multi-chain: Each parachain has its own endpoint; tools must handle multiple connections.
  • Ethereum compatibility: Polkadot Hub offers Ethereum JSON-RPC for EVM developers.
  • Substrate API Sidecar: Provides a RESTful alternative to raw JSON-RPC for easier integration.

Frequently Asked Questions

What is the official Polkadot RPC endpoint?

The official public RPC endpoint for Polkadot mainnet is wss://rpc.polkadot.io (WebSocket) and https://rpc.polkadot.io (HTTP). For Polkadot Hub's Ethereum-compatible RPC, use https://eth-rpc.polkadot.io. However, for production applications, it is recommended to use a managed provider like OnFinality for better reliability and performance.

How do I find the available RPC methods on a Polkadot node?

You can call the `rpc.methods()` JSON-RPC method on any node to retrieve a list of all available methods. Alternatively, the polkadot.js documentation provides a comprehensive reference of standard methods, though actual availability depends on the node's configuration and enabled pallets.

Can I use Ethereum tools like MetaMask with Polkadot?

Yes, Polkadot Hub supports Ethereum JSON-RPC compatibility, allowing you to use MetaMask, Hardhat, and other Ethereum tools. You need to configure your wallet with the Polkadot Hub RPC URL (e.g., https://eth-rpc.polkadot.io) and the correct chain ID (420420419 for mainnet).

What is the difference between a shared and dedicated Polkadot RPC node?

A shared RPC node is used by multiple customers and may have rate limits or performance variability. A dedicated node provides exclusive access to a node instance, ensuring consistent performance, higher request limits, and full control over node configuration. Dedicated nodes are recommended for high-traffic production applications.

How do I get testnet tokens for Polkadot?

Testnet tokens (PAS for Paseo) can be obtained from the Polkadot Faucet at https://faucet.polkadot.io. You will need to select the appropriate network and provide your account address. Testnet tokens are free and used for development and testing.

polkadot rpc
RPC Knowledge Base

Related RPC details

Background

Nunca te preocupes por la infraestructura nuevamente

OnFinality elimina la carga pesada de DevOps para que puedas construir de forma más inteligente y rápida.

Comenzar