chain_subscribeNewHeads - JSON-RPC Method
Description
Subscribe to a stream of new block headers. Requires WebSocket.
WebSocket Example (raw JSON-RPC)
const ws = new WebSocket('wss://api-acala.n.dwellir.com/YOUR_API_KEY');
ws.onopen = () => {
ws.send(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'chain_subscribeNewHeads', params: [] }));
};
ws.onmessage = (evt) => console.log(JSON.parse(evt.data));
@polkadot/api Example
const unsub = await api.rpc.chain.subscribeNewHeads((h) => console.log(`#${h.number}`));