Verifiable RPC Quickstart
Adding Verifiable RPC is a one-line change. Swap your ethers or viem client for the vRPC drop-in, or put the local verifying proxy in front of any other client, and every existing call keeps working, now verified fail-closed over the exact node-signed bytes before the data reaches your code.
:::info Access
Verifiable RPC is open to every Premium API key on Arbitrum, BNB Smart Chain and Polygon: call https://rpc.ankr.com/<chain>_vrpc/YOUR_ANKR_API_KEY (arbitrum_vrpc, bsc_vrpc, polygon_vrpc). Each request costs 3x the standard rate, 600 API credits on EVM chains, see Pricing. For another chain or a dedicated node, contact the Ankr team.
:::
Packages
All packages are published to npm under the @w3tech.io scope.
@w3tech.io/vrpc-ethers:VrpcProvider, a drop-inJsonRpcProviderfor ethers v6 (ethers ^6.16.0as a peer dependency).@w3tech.io/vrpc-viem:vrpcHttp, a drop-in transport for viem (viem ^2.55.1as a peer dependency).@w3tech.io/vrpc-core: the verification engine, for your own adapter or for responses captured outside a client;ConfidentialClientlives in the@w3tech.io/vrpc-core/confidentialentry.@w3tech.io/vrpc-proxy: a local verifying proxy for any language, as an npm CLI or the Docker imageghcr.io/w3tech/vrpc-proxy.@w3tech.io/dstack-verify: attestation checks; installed with core, you do not import it directly.
Install only the adapter you use. The adapters declare ethers and viem as peer dependencies, so installing one never pulls in the other:
# ethers users
npm install @w3tech.io/vrpc-ethers @w3tech.io/vrpc-core ethers
# viem users
npm install @w3tech.io/vrpc-viem @w3tech.io/vrpc-core viem
# your own adapter, or verifying captured responses
npm install @w3tech.io/vrpc-core
Requirements:
- Node
^22.16.0or>=24; the proxy needs Node>=24. Browsers: Chrome 116, Firefox 124, Safari 17.4 or later (a globalfetchis required). - Run vRPC from a server or a Node.js process. The public endpoint does not yet expose the
vRPC-*response headers to pages on other origins, so a browser page served from your own domain cannot verify responses. - Keep
@w3tech.io/vrpc-coreand the adapter at the same version, so the error classes keep one identity andinstanceofworks. - Upgrading from 0.3: read MIGRATION.md in the SDK repository. The error classes changed.
Endpoint and API key
You pass the vRPC route of your chain, for example https://rpc.ankr.com/arbitrum_vrpc. The SDK uses it as given and derives only <url>/attestation; it does not append _vrpc. Put the key in the path or in an x-api-key header. In Ankr Confidential RPC mode the SDK also derives <url>/confidential.
- Key in the path:
https://rpc.ankr.com/arbitrum_vrpc/<YOUR_KEY>. - Key in a header:
https://rpc.ankr.com/arbitrum_vrpcwithx-api-key: <YOUR_KEY>. With ethers the header goes on aFetchRequest; with viem in the transport'sheaders.
A plain route such as https://rpc.ankr.com/arbitrum returns unsigned answers, and the SDK rejects them with MissingHeader.
Pin the chain id (42161 for Arbitrum One). It is bound into every signature, so a wrong one fails as BadSignature, and pinning it catches a wrong-URL misconfiguration that would otherwise verify genuine data from the wrong chain. In open mode it is optional: if you omit it, the SDK derives it from a signed eth_chainId response on first use. Ankr Confidential RPC requires it. The adapters accept number | bigint | string. In ethers the id must be an integer ("-239" for TON and "0x89" are fine); the core verifier and viem take the exact configured string.
ethers v6
// Before: new JsonRpcProvider(url)
import { VrpcProvider } from "@w3tech.io/vrpc-ethers";
const key = process.env.ANKR_API_KEY!;
const provider = new VrpcProvider(`https://rpc.ankr.com/arbitrum_vrpc/${key}`, 42161);
console.log(await provider.getBlockNumber());
With the key in a header instead:
import { FetchRequest } from "ethers";
import { VrpcProvider } from "@w3tech.io/vrpc-ethers";
const req = new FetchRequest("https://rpc.ankr.com/arbitrum_vrpc");
req.setHeader("x-api-key", process.env.ANKR_API_KEY!);
const provider = new VrpcProvider(req, 42161);
VrpcProvider extends JsonRpcProvider. Everything downstream, getBalance, call, getBlock, getLogs, contract reads, polling, is unchanged; the raw response bytes are verified before they are parsed.
viem
// Before: transport: http(url)
import { createPublicClient } from "viem";
import { arbitrum } from "viem/chains";
import { vrpcHttp } from "@w3tech.io/vrpc-viem";
const client = createPublicClient({
chain: arbitrum,
transport: vrpcHttp("https://rpc.ankr.com/arbitrum_vrpc", {
headers: { "x-api-key": process.env.ANKR_API_KEY! },
}),
});
console.log(await client.getBlockNumber());
vrpcHttp substitutes for http. Every viem action (getBalance, readContract, getLogs, getBlock, estimateGas, getTransactionReceipt, sendRawTransaction, and so on) goes through its single verifying request. The chain id comes from the client's chain.
Any language: the local proxy
vrpc-proxy verifies on behalf of any client, in any language, REST included. Start it next to your application and point your client at http://127.0.0.1:8969:
npx @w3tech.io/vrpc-proxy --upstream https://rpc.ankr.com/arbitrum_vrpc --chain-id 42161 --api-key "$ANKR_API_KEY"
Or with Docker (the image listens on 0.0.0.0:8969 and is amd64 only; publish the port on localhost so nobody else can spend your key through it):
docker run --rm -p 127.0.0.1:8969:8969 ghcr.io/w3tech/vrpc-proxy:0.4.0 --upstream https://rpc.ankr.com/arbitrum_vrpc --chain-id 42161 --api-key "$ANKR_API_KEY"
curl -s http://127.0.0.1:8969 -H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}'
One proxy serves one chain. A response that fails verification is never relayed: the client gets a typed JSON error ({"error":{"kind":"BadSignature",...}}) with HTTP 502 instead. Other flags: --listen, --timeout, --replay-window, --attestation-cache-ttl, --log-level, --max-body-bytes, and --confidential for Ankr Confidential RPC.
Errors
A failed check throws a VerificationError subclass: BadSignature, StaleTimestamp, MissingHeader, MalformedHeader, AttestationFailed, and others. No unverified value is ever returned. Every SDK error extends the root VrpcError and carries a kind you can switch on; invalid options throw InvalidOption from the constructor.
If the attestation cannot be fetched or checked right now, including a verifier outage, the call throws AttestationUnavailable. It is an UnavailableError, not a VerificationError, so catch (e instanceof VerificationError) does not catch it. Treat it as transient.
WebSocket subscriptions and ENS off-chain reads are outside the signed path; see What is verified.
Verify it yourself
To verify a response outside an ethers or viem call, for example in an audit script or an off-chain pipeline, use verifyResponse from @w3tech.io/vrpc-core. Hand it the content-decoded request bytes, the response bytes and the response headers; it rebuilds the signed fingerprint, checks the Ed25519 signature and enforces the replay window, all fail-closed.
import { verifyResponse, VerificationError } from "@w3tech.io/vrpc-core";
declare const requestBytes: Uint8Array; // the exact request body you sent
declare const responseBytes: Uint8Array; // the exact, content-decoded response body
declare const responseHeaders: Headers;
try {
const pair = await verifyResponse(requestBytes, responseBytes, responseHeaders, {
chainId: "42161", // the exact string the node signs with
});
console.log(pair.verification.pubkeyHex, pair.nodeId);
} catch (err) {
if (err instanceof VerificationError) {
console.error(err.kind, err.message);
}
throw err;
}
verifyResponse checks the signature only. It does not fetch the attestation, so it proves the bytes were signed by vRPC-Pubkey, not that the key lives in an attested enclave; the adapters and the proxy do both. Because it is byte-level, it verifies JSON-RPC POSTs and path-based REST responses alike. For a GET, the request body is empty, so pass an empty Uint8Array.
Next steps
- Read What is verified and the Trust model before you rely on the signature.
- Encrypt every call with Ankr Confidential RPC.
- Browse the SDK, every option and error, and runnable examples at github.com/w3tech/verifiable-rpc-sdk.