eth_subscribe("newHeads")
JSON-RPC method allows developers to receive real-time notifications regarding new block headers on the Hyperliquid EVM blockchain. It sends notifications whenever a new block is added, making it essential for applications that need to track blockchain state changes in real-time.
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
- subscription type (string, required): Keyword identifying the type of event to subscribe to,
newHeads
in this case
Response
The method returns a subscription ID that can be used to identify and manage the subscription.Response structure
Initial subscription response:subscription
— the subscription ID
number
— block number of the requested block, encoded as hexadecimalhash
— block hash of the requested blockparentHash
— hash of the previous blocknonce
— proof-of-work hash (0x0000000000000000 for proof-of-stake)sha3Uncles
— hash of the list of uncles included in the blocklogsBloom
— bloom filter for the logs of the blocktransactionsRoot
— root of the transaction trie of the blockstateRoot
— root of the final state trie of the blockreceiptsRoot
— root of the receipts trie of the blockminer
— address of the miner receiving the rewarddifficulty
— block difficulty (legacy field, typically 0x0 for PoS)totalDifficulty
— null (obsolete after merge to PoS)extraData
— extra data included by the minersize
— size of this block in bytesgasLimit
— maximum gas allowed in this blockgasUsed
— total used gas by all transactionstimestamp
— Unix timestamp for when the block was collated
Usage example
Basic implementation
Note that subscriptions require a WebSocket connection. Install WebSocket cat for testing:
wscat
JavaScript implementation
Python implementation
Use cases
Theeth_subscribe("newHeads")
method is essential for applications that need to:
- Monitor blockchain state: Track new blocks as they are added to the chain
- Calculate confirmations: Count confirmations for transactions by tracking subsequent blocks
- Build real-time dashboards: Display current block height, gas prices, and network activity
- Trigger automated actions: Execute smart contract interactions when new blocks arrive
- Index blockchain data: Update databases with the latest blockchain state
- Monitor network health: Track block production rate and validator performance
- Implement event listeners: Process events more efficiently by focusing on specific block ranges
- Build trading bots: React to new blocks for time-sensitive DeFi operations
- Track finality: Monitor block finalization in proof-of-stake networks
- Analyze gas trends: Monitor gas usage patterns across blocks