chain_subscribeFinalizedHeads
Description
Creates a subscription that pushes every newly finalized block header. Useful for indexers that only act on finalized data.
Parameters
This method does not require parameters.
Notification Payload
Field | Type | Description |
---|---|---|
number | string | Block number in hex |
hash | string | Block hash |
parentHash | string | Parent block hash |
stateRoot | string | State root |
digest | object | Consensus digest items |
JavaScript Example
import { ApiPromise, WsProvider } from '@polkadot/api';
const provider = new WsProvider('wss://api-astar.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });
api.rpc.chain.subscribeFinalizedHeads((header) => {
console.log(`Finalized block #${header.number.toString()} (${header.hash.toHex()})`);
});
WebSocket JSON-RPC Example
{
"jsonrpc": "2.0",
"id": 1,
"method": "chain_subscribeFinalizedHeads",
"params": []
}
A notification payload will arrive on the same connection with method: "chain_finalizedHead"
and the header data in params.result
.