DEV Community

OnFinality
OnFinality

Posted on Originally published at onfinality.io

ZKsync RPC: Endpoints, Chain Settings, and Debugging

ZKsync is an Ethereum Layer 2 scaling solution that uses zero-knowledge proofs to offer low-cost, high-throughput transactions. This article covers the essential RPC endpoints, chain settings, and JSON-RPC methods you need to connect your dApp or wallet to ZKsync mainnet and testnet, plus common pitfalls and how to choose a reliable RPC provider.

Quick decision guide: which ZKsync RPC should you use?

Before diving into configuration, decide which endpoint fits your use case. If you are building a production dApp, a public endpoint like https://zksync.api.onfinality.io/public is fine for prototyping, but for sustained traffic you should evaluate a managed RPC provider that offers higher rate limits, WebSocket support, and dedicated infrastructure. For testnet development, use the Sepolia endpoint and fund your wallet from a faucet. If you need archive data or trace methods, confirm the provider supports them—many shared endpoints do not.

ZKsync chain settings at a glance

Here are the key network parameters for ZKsync mainnet and testnet. Use these when adding the network to a wallet or configuring your dApp.

Property ZKsync Mainnet ZKsync Sepolia Testnet
Chain ID 324 300
Network Name ZKsync Era Mainnet ZKsync Era Sepolia
Native Currency ETH ETH
RPC URL https://zksync.api.onfinality.io/public https://zksync-sepolia.api.onfinality.io/public
WebSocket URL wss://zksync.api.onfinality.io/public wss://zksync-sepolia.api.onfinality.io/public
Block Explorer https://explorer.zksync.io https://sepolia.explorer.zksync.io

Note: The WebSocket URLs above are the standard pattern for OnFinality public endpoints; verify the exact URL on the ZKsync network page if you need a WebSocket connection.

What is ZKsync and why does it need a special RPC?

ZKsync is a ZK-rollup that batches transactions off-chain and generates validity proofs that are verified on Ethereum. This architecture gives you Ethereum-level security with lower fees and higher throughput. Because ZKsync is EVM-compatible, most standard Ethereum JSON-RPC methods work, but ZKsync also introduces custom methods (prefixed with zks_) to interact with rollup-specific features like bridges and L2-to-L1 proofs. Your RPC endpoint must support these methods to fully integrate with the network.

Connecting to ZKsync: wallet and dApp configuration

To connect a wallet like MetaMask, add a custom network with the chain settings above. For a dApp, configure your provider using the RPC URL. Here is an example using ethers.js:

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://zksync.api.onfinality.io/public");

async function getBlockNumber() {
  const blockNumber = await provider.getBlockNumber();
  console.log("Current block:", blockNumber);
}

getBlockNumber();
Enter fullscreen mode Exit fullscreen mode

For viem:

import { createPublicClient, http } from 'viem';
import { zksync } from 'viem/chains';

const client = createPublicClient({
  chain: zksync,
  transport: http('https://zksync.api.onfinality.io/public')
});

const blockNumber = await client.getBlockNumber();
console.log(blockNumber);
Enter fullscreen mode Exit fullscreen mode

ZKsync JSON-RPC methods you should know

Beyond standard Ethereum methods, ZKsync provides custom methods for rollup-specific operations. Here are a few essential ones:

  • zks_getBridgeContracts – returns the L1/L2 bridge contract addresses.
  • zks_getL2ToL1LogProof – retrieves the proof for an L2-to-L1 message, needed for cross-chain operations.
  • zks_estimateGasL1ToL2 – estimates gas for a transaction from L1 to L2.
  • zks_getBlockDetails – returns detailed information about a specific block.

Example request using curl:

curl -X POST https://zksync.api.onfinality.io/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"zks_getBridgeContracts","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

Common failure modes and how to debug them

When working with ZKsync RPC, you may encounter these issues:

  • Method not supported: Some providers do not implement zks_* methods. Check the provider's documentation or switch to a provider that explicitly supports ZKsync.
  • Rate limiting: Public endpoints often have strict rate limits. If you see HTTP 429 errors, consider upgrading to a paid plan or using a dedicated node.
  • WebSocket disconnects: For real-time updates, ensure your WebSocket URL is correct and your client handles reconnection.
  • Chain ID mismatch: If your wallet shows the wrong network, verify the chain ID (324 for mainnet, 300 for Sepolia).

Choosing a reliable ZKsync RPC provider

For production applications, relying on a public endpoint is risky due to rate limits and potential downtime. When evaluating providers, consider:

  • Uptime and reliability: Look for providers with a track record of high availability.
  • Rate limits and quotas: Understand the request limits and whether they fit your traffic.
  • WebSocket support: Needed for real-time subscriptions.
  • Archive data: If you need historical state, ensure the provider offers archive nodes.
  • Custom methods: Confirm support for zks_* methods.

OnFinality offers a managed RPC service with public endpoints for ZKsync and many other networks. For production workloads, you can explore dedicated nodes or RPC pricing to find a plan that matches your needs. See the full list of supported networks to check availability.

Key Takeaways

  • ZKsync mainnet uses chain ID 324, and Sepolia testnet uses 300.
  • Public endpoints like https://zksync.api.onfinality.io/public are suitable for development, but production apps should consider a managed provider.
  • ZKsync has custom JSON-RPC methods (zks_*) that are essential for bridge and proof operations.
  • Always verify that your RPC provider supports WebSocket and archive data if your dApp requires them.

Frequently Asked Questions

What is the ZKsync RPC URL?
The public RPC URL for ZKsync mainnet is https://zksync.api.onfinality.io/public. For Sepolia testnet, use https://zksync-sepolia.api.onfinality.io/public.

What is the ZKsync chain ID?
The chain ID for ZKsync mainnet is 324, and for Sepolia testnet it is 300.

Does ZKsync support WebSocket?
Yes, ZKsync supports WebSocket connections for real-time updates. Use the wss:// URL provided by your RPC provider.

What are ZKsync-specific RPC methods?
ZKsync adds methods prefixed with zks_, such as zks_getBridgeContracts and zks_getL2ToL1LogProof, to interact with rollup features.

Can I use standard Ethereum RPC methods on ZKsync?
Yes, ZKsync is EVM-compatible, so most Ethereum methods like eth_blockNumber and eth_call work. However, some methods may behave differently due to the rollup architecture.

Related resources

Originally published at OnFinality.

Top comments (0)