WebSockets

Subscriptions instead of polling — for wallets, indexers and anything that waits for events.

Copy the WebSocket URL from the testnet page (under the RPC endpoint). It is signed for that one testnet and is good for 24 hours; reload the page for a fresh one. The same connection answers ordinary calls too.

ts
import { WebSocketProvider } from "ethers";

const provider = new WebSocketProvider(process.env.FORKSTATE_WS!);
provider.on("block", (number) => console.log("new block", number));

Subscriptions

SubscriptionSends
newHeadsThe header of every block the testnet mines
logsLogs matching { address, topics }
newPendingTransactionsThe hash of each transaction
  • topics is positional; each position can be a topic, null for anything, or a list meaning “any of these”.
  • A testnet mines as it receives, so a pending transaction is announced when its block is made.
  • Up to 64 subscriptions per connection. A ping every 30 seconds keeps an idle one open.
If the account runs out of credit, open sockets are closed with code 4402 and new ones are refused until credit is added.