For the complete documentation index, see llms.txt. This page is also available as Markdown.

newBlocks - EVM Data Stream

Stream every new full block, with transaction objects, over WebSocket. Complete guide on how to use the newBlocks topic in GetBlock EVM Data Stream documentation.

The newBlocks topic sends one notification per new block, carrying the full block with every transaction as a complete object. Use it when you index everything in a block and would otherwise call eth_getBlockByNumber(…, true) after each header.

Full blocks are large: an Ethereum block is often several hundred kilobytes of JSON. If you only need a block signal, use newHeads. If you only need some transactions, use newMinedTransactions with address rules.

Parameters

newBlocks accepts no parameters. Send only the topic name; any other field is rejected.

Request Example

# WebSocket-only. Connect first:
wscat -c 'wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream' -H 'Authorization: Bearer <API-KEY>'

# Then send:
{"jsonrpc":"2.0","id":1,"method":"getblock_subscribe","params":[{"topic":"newBlocks"}]}
// npm install ws
import WebSocket from 'ws';

const ws = new WebSocket('wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream', {
  headers: { Authorization: 'Bearer <API-KEY>' }
});

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

ws.on('message', (raw) => {
  const msg = JSON.parse(raw);

  // First reply is the subscription ID (or an error)
  if (msg.id !== undefined) {
    console.log(msg.error ?? `Subscribed: ${msg.result}`);
    return;
  }

  const { removed, data } = msg.params.result;
  console.log(removed ? 'REMOVED' : 'block', parseInt(data.number, 16), `${data.transactions.length} txs`);
});

Response Example

The first reply is the subscription ID:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x5f020d44c27b974318b8da1cc04c3e75"
}

Every later message is an event notification (transactions and withdrawals shortened to one entry each):

Response Parameters

The result object contains the event envelope and the payload in data.

Field
Type
Description

eventId

string

Stable event identifier. A reorg correction reuses it.

removed

boolean

true when a reorg removed this previously delivered event.

revision

number

Event version. For one eventId, a greater revision is newer.

data

object

Full block, in the same shape as eth_getBlockByNumber(…, true). It has every [newHeads](newheads-evm-data-stream.md) header field plus the fields below.

data.transactions

array

Every transaction in the block as a full object, in block order. Same shape as the transaction object in [newMinedTransactions](newminedtransactions-evm-data-stream.md#response-parameters).

data.withdrawals

array

Validator withdrawals processed in the block, each with index, validatorIndex, address, and amount (in gwei, hex-encoded). Present where the network has withdrawals.

data.uncles

array

Uncle block hashes. Always empty on proof-of-stake Ethereum.

data.size

string

Block size in bytes, hex-encoded.

Use Cases

  • Indexing every transaction on a network without follow-up RPC calls

  • Block explorers and analytics pipelines

  • Computing per-block statistics such as transaction count, fees, and top senders

  • Keeping a local database in sync with the chain tip

Error Handling

Code
Message
Cause

-32602

invalid newBlocks request: json: unknown field "…"

newBlocks takes no parameters.

-32602

invalid newBlocks request: json: unknown field "…"

The request has a field this topic does not accept.

-32001

subscription limit exceeded

You already have 15 active or pending subscriptions.

Last updated

Was this helpful?