githubEdit

eth_subscribe - Celo

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 real-time event notifications on the Celo network.

circle-info

This requires a WebSocket connection and is ideal for tracking new blocks, pending transactions, or contract events with Celo's fast ~1 second block times.

Parameters

Parameter
Type
Required
Description

subscriptionType

string

Yes

Type: "newHeads", "logs", "newPendingTransactions"

options

object

No

Filter options (for "logs" type)

Request Example

subscribe-newHeads.js
const WebSocket = require('ws');

const ws = new WebSocket('wss://go.getblock.io/<ACCESS-TOKEN>/');

ws.on('open', () => {
  ws.send(JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'eth_subscribe',
    params: ['newHeads']
  }));
});

ws.on('message', (data) => {
  console.log(JSON.parse(data));
});

Response Example

Response Definition

Field
Type
Description

result

string

Subscription ID

Use Cases

  • Real-time block notifications

  • Live stablecoin transfer tracking

  • Pending transaction monitoring

  • DeFi event streaming

Error Handling

Error Code
Description

-32602

Invalid subscription type

-32603

Internal error

SDK Integration

Last updated

Was this helpful?