Logo

Starknet RPC: Endpoints, Providers, and Best Practices

摘要

Starknet is a ZK-rollup on Ethereum that uses STARK proofs for scalability. To interact with Starknet, you need an RPC endpoint. This guide covers public and private Starknet RPC endpoints, how to choose a provider, and common troubleshooting tips for developers.

Starknet RPC Decision Checklist

Before integrating a Starknet RPC provider, consider these criteria:

CriterionWhat to checkWhy it matters
Network supportMainnet, Sepolia testnetEnsure the provider supports the networks you need for development and production.
Rate limitsRequests per second (RPS) and daily capHigh-traffic dApps require higher limits to avoid throttling.
ReliabilityUptime history, redundancyDowntime can disrupt your application; choose providers with proven reliability.
LatencyGeographic distribution of nodesLower latency improves user experience, especially for time-sensitive operations.
Archive dataAccess to historical stateNeeded for analytics, explorers, and certain dApp features.
Pricing modelFree tier, pay-as-you-go, or dedicated nodeMatch the pricing to your usage pattern and budget.
API compatibilityJSON-RPC methods supportedVerify that the provider supports the methods your application requires.
SecurityHTTPS, WebSocket support, privacy featuresProtect data in transit and consider privacy-focused relays if needed.

What is Starknet RPC?

Starknet RPC (Remote Procedure Call) is the standard interface for communicating with the Starknet network. It allows wallets, dApps, and backend services to submit transactions, query account balances, read contract state, and interact with smart contracts. The RPC protocol follows the JSON-RPC 2.0 specification, with Starknet-specific methods defined in the Starknet API specification.

Starknet uses a unique account abstraction model where every account is a smart contract. This means RPC interactions often involve deploying and invoking contracts through the starknet_call and starknet_sendTransaction methods.

Starknet RPC Endpoints

Starknet provides both public and private RPC endpoints. Public endpoints are free but often have rate limits and may not be suitable for production. Private endpoints offer higher limits, dedicated resources, and better reliability.

Public Endpoints

  • https://public.1rpc.io/starknet (1RPC)
  • https://starknet-rpc.publicnode.com (Allnodes)
  • https://starknet.drpc.org (dRPC)
  • https://rpc.starknet.lava.build (Lava)
  • https://starknet.api.onfinality.io/public (OnFinality)

Private Endpoints (require API key)

  • https://starknet-mainnet.g.alchemy.com/v2/<api-key> (Alchemy)
  • https://starknet-mainnet.infura.io/v3/<api-key> (Infura)
  • https://starknet.api.onfinality.io/v1/<api-key> (OnFinality)

Testnet (Sepolia)

  • https://starknet-sepolia-rpc.publicnode.com (Allnodes)
  • https://rpc.starknet-testnet.lava.build (Lava)
  • https://starknet-sepolia.api.onfinality.io/public (OnFinality)

How to Use Starknet RPC

To connect to Starknet, you need an RPC URL and a JSON-RPC client. Below is an example using curl to query the latest block number.

curl https://starknet.api.onfinality.io/public \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "starknet_blockNumber",
    "params": [],
    "id": 1
  }'

For JavaScript (using ethers or starknet.js):

import { Provider } from 'starknet';

const provider = new Provider({
  rpc: { nodeUrl: 'https://starknet.api.onfinality.io/public' }
});

const blockNumber = await provider.getBlockNumber();
console.log(blockNumber);

Choosing a Starknet RPC Provider

When selecting a provider, consider the following factors:

  • Network Support: Ensure the provider supports Starknet mainnet and testnet (Sepolia).
  • Rate Limits: Free tiers typically allow 10-100 requests per second. For high-traffic dApps, look for paid plans or dedicated nodes.
  • Reliability: Check uptime history and whether the provider offers redundancy across multiple data centers.
  • Latency: Providers with global node distribution can offer lower latency.
  • Archive Data: Some providers offer access to historical state, which is essential for analytics and explorers.
  • Pricing: Compare free tiers, pay-as-you-go, and dedicated node pricing. OnFinality offers transparent pricing for Starknet RPC.

For a detailed comparison of RPC providers, see our guide on choosing an RPC provider.

Common Pitfalls and Troubleshooting

1. Rate Limiting

Public endpoints often have strict rate limits. If you receive HTTP 429 errors, consider upgrading to a private endpoint or using a dedicated node.

2. Incorrect Network ID

Starknet mainnet chain ID is 0x534e5f4d41494e (SN_MAIN). Sepolia testnet chain ID is 0x534e5f5345504f4c4941 (SN_SEPOLIA). Double-check your configuration.

3. Unsupported Methods

Not all providers support every JSON-RPC method. For example, starknet_getStateUpdate may be unavailable on some public endpoints. Check the provider's documentation.

4. WebSocket Connections

For real-time updates, use WebSocket endpoints. Example:

wss://starknet.api.onfinality.io/public/ws

5. Transaction Failures

Starknet transactions can fail due to insufficient fees, invalid nonce, or contract errors. Use starknet_getTransactionReceipt to debug.

Starknet RPC vs. Other Networks

Starknet's RPC differs from Ethereum's in several ways:

  • Account abstraction: Every account is a contract; transactions are invoked via starknet_addInvokeTransaction.
  • Fee model: Starknet uses a separate fee token (STRK) and a unique fee calculation.
  • Block time: Blocks are produced every 20-60 seconds, faster than Ethereum.

Key Takeaways

  • Starknet RPC is essential for interacting with the Starknet network.
  • Choose a provider based on network support, rate limits, reliability, and pricing.
  • Public endpoints are suitable for development; private endpoints are recommended for production.
  • Always test with a testnet before deploying to mainnet.
  • OnFinality provides scalable Starknet RPC endpoints with transparent pricing. Check our supported networks and pricing for more details.

FAQ

What is the Starknet RPC URL?

Public Starknet mainnet RPC URLs include https://starknet.api.onfinality.io/public, https://public.1rpc.io/starknet, and https://starknet.drpc.org. Private endpoints require an API key.

How do I get a Starknet RPC endpoint?

You can use a public endpoint for free or sign up with a provider like OnFinality to get a private endpoint with higher rate limits and dedicated support.

Is Starknet RPC compatible with MetaMask?

No, MetaMask only supports EVM-compatible chains. Starknet uses a different virtual machine (Cairo VM), so you need a Starknet-compatible wallet like Argent X or Braavos.

What is the difference between Starknet mainnet and Sepolia testnet?

Mainnet is the production network with real assets. Sepolia is a testnet for development and testing. Both have separate RPC endpoints.

How do I choose between public and private RPC?

Use public endpoints for prototyping and low-traffic applications. For production dApps with high traffic, choose a private endpoint or dedicated node to ensure reliability and performance.

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 的繁重工作,让您能够更聪明、更快地构建。

开始