Docs
Supported ChainsAsset HubSubstrate APIChain Methods

chain_subscribeNewHeads - Asset Hub RPC Method

Subscribe to new block headers on Asset Hub. Real-time notifications for new blocks as they are produced.

Subscribe to receive notifications when new block headers are produced on Asset Hub. This WebSocket subscription provides real-time updates for each new block.

Use Cases

  • Block monitoring - Track new blocks in real-time for native stablecoin transfers (USDC, USDT), DOT staking and governance, and cross-chain asset management via XCM
  • Event indexing - Trigger processing when new blocks arrive
  • Chain synchronization - Keep external systems in sync with the chain

Request Parameters

Request

This method accepts no parameters.

Response Body

Response
parentHashHash

Parent block hash

numberBlockNumber

Block number

stateRootHash

State trie root hash

extrinsicsRootHash

Extrinsics trie root hash

digestDigest

Block digest with consensus logs

Code Examples

JavaScript
import { ApiPromise, WsProvider } from '@polkadot/api';

const provider = new WsProvider('wss://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });

// Subscribe to new heads
const unsubscribe = await api.rpc.chain.subscribeNewHeads((header) => {
  console.log(`New block #${header.number}`);
  console.log(`  Hash: ${header.hash.toHex()}`);
  console.log(`  Parent: ${header.parentHash.toHex()}`);
  console.log(`  State root: ${header.stateRoot.toHex()}`);
});

// Later: unsubscribe()
Python
import asyncio
import websockets
import json

async def subscribe_new_heads():
    uri = 'wss://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY'

    async with websockets.connect(uri) as ws:
        # Subscribe to new heads
        await ws.send(json.dumps({
            'jsonrpc': '2.0',
            'method': 'chain_subscribeNewHeads',
            'params': [],
            'id': 1
        }))

        # Get subscription ID
        response = json.loads(await ws.recv())
        sub_id = response['result']
        print(f'Subscribed with ID: {sub_id}')

        # Listen for new headers
        while True:
            message = json.loads(await ws.recv())
            if 'params' in message:
                header = message['params']['result']
                print(f"Block #{int(header['number'], 16)}")
                print(f"  Hash: {header['parentHash']}")

asyncio.run(subscribe_new_heads())

Subscription vs Polling

ApproachLatencyResource UsageUse Case
subscribeNewHeadsImmediateLow (push-based)Real-time monitoring
Polling getHeaderBlock time + poll intervalHigher (repeated requests)Simple integrations