Starknet RPC: Endpoints, Providers, and Best Practices
Resumen
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:
| Criterion | What to check | Why it matters |
|---|---|---|
| Network support | Mainnet, Sepolia testnet | Ensure the provider supports the networks you need for development and production. |
| Rate limits | Requests per second (RPS) and daily cap | High-traffic dApps require higher limits to avoid throttling. |
| Reliability | Uptime history, redundancy | Downtime can disrupt your application; choose providers with proven reliability. |
| Latency | Geographic distribution of nodes | Lower latency improves user experience, especially for time-sensitive operations. |
| Archive data | Access to historical state | Needed for analytics, explorers, and certain dApp features. |
| Pricing model | Free tier, pay-as-you-go, or dedicated node | Match the pricing to your usage pattern and budget. |
| API compatibility | JSON-RPC methods supported | Verify that the provider supports the methods your application requires. |
| Security | HTTPS, WebSocket support, privacy features | Protect 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.