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

nextBlock - Cardano

Example code for the nextBlock WebSocket method. Complete guide on how to use nextBlock WebSocket in GetBlock Web3 documentation.

This method requests the next chain-synchronization instruction. The node responds with either a forward roll to the next block or a backward roll to a previous point after a reorganization. This protocol requires a WebSocket connection.

Parameters

This method does not require parameters.

Request

example.js
import WebSocket from 'ws';

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

client.once('open', () => {
    client.send(JSON.stringify({"jsonrpc": "2.0", "method": "nextBlock", "id": "getblock.io"}));
});

client.on('message', (msg) => {
    console.log(JSON.parse(msg.toString()));
    client.close();
});
example.py
import asyncio
import json
import websockets

async def main():
    async with websockets.connect('wss://go.getblock.io/<ACCESS-TOKEN>/') as ws:
        await ws.send(json.dumps({"jsonrpc": "2.0", "method": "nextBlock", "id": "getblock.io"}))
        print(json.loads(await ws.recv()))

asyncio.run(main())

Response

Response Parameters

Field
Type
Description

direction

string

forward for a new block, or backward for a rollback

block

object

The block rolled forward to, present on a forward roll

point

object

The point rolled back to, present on a backward roll

tip

object

The node's current tip

Use Cases

  • Chain Indexing: Stream blocks sequentially into an off-chain store

  • Reorg Handling: React to backward rolls by rewinding local state

  • Event Pipelines: Drive downstream processing from each new block

  • Explorers: Ingest the chain block by block

Error Handling

Error Code
Message
Description

-32602

Invalid params

The supplied points are missing or malformed

1000

Intersection not found

None of the supplied points are on the node's chain

-32603

Internal error

The node failed to advance the chain-sync protocol

Last updated

Was this helpful?