eth_subscribe - Soneium

This method opens a push subscription over a WebSocket connection and returns a subscription ID. Supported event types are newHeads, logs, newPendingTransactions, and syncing. It requires a wss:// endpoint rather than HTTP.

This method works only over a WebSocket connection. Use the wss:// form of the endpoint (wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/) rather than HTTPS.

Parameters

ParameterTypeRequiredDescription
subscriptionTypestringYesOne of newHeads, logs, newPendingTransactions, syncing
optionsobjectNoFilter options (used with the logs subscription)

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_subscribe",
    "params": ["logs", { "address": "0x4200000000000000000000000000000000000006", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] }],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_subscribe',
    params: ['logs', { address: '0x4200000000000000000000000000000000000006', topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'] }],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_subscribe',
        'params': ['logs', { 'address': '0x4200000000000000000000000000000000000006', 'topics': ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'] }],
        'id': 'getblock.io'
    }
)

print(response.json())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "eth_subscribe",
            "params": ["logs", { "address": "0x4200000000000000000000000000000000000006", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] }],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x9cef478923ff08bf67fde6c64013158d"
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultstringSubscription ID used to correlate pushed notifications

Use Cases

  • Live Heads: Receive newHeads pushes to follow the ~1 second block cadence
  • Event Streams: Stream matching logs without polling
  • Mempool Feeds: Receive newPendingTransactions as they arrive
  • Sync Monitoring: Watch syncing state transitions in real time

Error Handling

Error CodeMessageDescription
-32602Invalid paramsUnknown subscription type or malformed options
-32601Method not foundThe endpoint was called over HTTP instead of WebSocket

Web3 Integration

ethers-example.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const provider = new ethers.WebSocketProvider('wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
provider.on('block', (n) => console.log(n));

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';

const client = createPublicClient({
  transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const client = createPublicClient({ transport: webSocket('wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/') });
client.watchBlocks({ onBlock: (b) => console.log(b) });