eth_subscribe - ARC

Example code for the eth_subscribe JSON-RPC method. Complete guide on how to use eth_subscribe JSON-RPC in GetBlock Web3 documentation.

This method creates a real-time subscription over a WebSocket connection. Available subscription types are newHeads (new block headers), logs (matching contract events), and newPendingTransactions (pending transactions).

This method is only available over WebSocket transport — use wss://go.getblock.io/<ACCESS-TOKEN>/. With Arc's ~2 second block times, WebSocket subscriptions are the most efficient way to drive real-time payment UIs.

Parameters

Parameter
Type
Required
Description

subscriptionType

string

Yes

One of "newHeads", "logs", "newPendingTransactions"

filterObject

object

No

For "logs": filter with address and/or topics

Request Example

import axios from 'axios';

// Note: eth_subscribe requires WebSocket, but here's the message format
const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_subscribe",
    "params": ["newHeads"],
    "id": "getblock.io"
});

console.log('WebSocket message:', data);

Response Example

Response Parameters

Field
Type
Description

result

string

Subscription ID, used to match incoming eth_subscription notifications and to call eth_unsubscribe

Use Cases

  • Real-time merchant payment confirmation notifications

  • Live FX engine trade feeds for trading UIs

  • Streaming indexers that react to new blocks instantly

  • Compliance systems monitoring high-value transfers in real time

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32601

Method not found

The method is not supported by this node

429

Too Many Requests

Rate limit exceeded for your plan

-32600

Invalid Request

eth_subscribe was called over HTTP; use a WebSocket connection instead

SDK Integration

Last updated

Was this helpful?