eth_subscribe - Mantle

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 subscription for specific events on the blockchain.

Parameters

Parameter
Type
Description

subscriptionType

string

Type of subscription ("newHeads", "logs", "newPendingTransactions")

filterObject

object

(optional) Filter options for logs subscription

Request (WebSocket)

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);

Subscription Types

Type
Description

newHeads

Fires when new block is added to chain

logs

Fires when logs matching filter are included

newPendingTransactions

Fires when new pending tx is added to pool

Response

Notification Example (newHeads)

Response Parameters

Field
Type
Description

result

string

Subscription ID for managing the subscription

Use Case

The eth_subscribe method is essential for:

  • Real-time block monitoring

  • Event streaming

  • Live transaction tracking

  • DApp real-time updates

  • Notification systems

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32000

Subscription not supported

HTTP used instead of WebSocket

Web3 Integration

Last updated

Was this helpful?