Skip to main content

NewHeadsSubscription

subscribe('newHeads') ( same as subscribe('newBlockHeaders'))

Subscribes to incoming block headers. This can be used as timer to check for changes on the blockchain.

The structure of a returned block header is BlockHeaderOutput:

@example
(await web3.eth.subscribe('newHeads')).on( // 'newBlockHeaders' would work as well
'data',
console.log
);
>{
parentHash: '0x9e746a1d906b299def98c75b06f714d62dacadd567c7515d76eeaa8c8074c738',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
miner: '0x0000000000000000000000000000000000000000',
stateRoot: '0xe0f04b04861ecfa95e82a9310d6a7ef7aef8d7417f5209c182582bfb98a8e307',
transactionsRoot: '0x31ab4ea571a9e10d3a19aaed07d190595b1dfa34e03960c04293fec565dea536',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
difficulty: 2n,
number: 21n,
gasLimit: 11738125n,
gasUsed: 830006n,
timestamp: 1678797237n,
extraData: '0xd883010b02846765746888676f312e32302e31856c696e757800000000000000e0a6e93cf40e2e71a72e493272210c3f43738ccc7e7d7b14ffd51833797d896c09117e8dc4fbcbc969bd21b42e5af3e276a911524038c001b2109b63b8e0352601',
nonce: 0n
}

Hierarchy

Index

Constructors

constructor

Properties

readonlyargs

args: any

Accessors

id

  • get id(): undefined | string
  • Returns undefined | string

lastBlock

  • Returns undefined | BlockOutput

Methods

_processSubscriptionError

  • _processSubscriptionError(error: Error): void
  • Parameters

    • error: Error

    Returns void

_processSubscriptionResult

  • _processSubscriptionResult(data: unknown): void
  • Parameters

    • data: unknown

    Returns void

emit

  • emit<K>(eventName: K, params: { data: BlockHeaderOutput } & CommonSubscriptionEvents[K]): void

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listenerCount

  • listenerCount<K>(eventName: K): number
  • Type parameters

    Parameters

    • eventName: K

    Returns number

listeners

  • listeners<K>(eventName: K): (...args: any[]) => void[]
  • Type parameters

    Parameters

    • eventName: K

    Returns (...args: any[]) => void[]

off

on

once

processSubscriptionData

removeAllListeners

  • Returns EventEmitter

resubscribe

  • resubscribe(): Promise<void>
  • Returns Promise<void>

sendSubscriptionRequest

  • sendSubscriptionRequest(): Promise<string>
  • Returns Promise<string>

sendUnsubscribeRequest

  • sendUnsubscribeRequest(): Promise<void>
  • Returns Promise<void>

setMaxListenerWarningThreshold

  • setMaxListenerWarningThreshold(maxListenersWarningThreshold: number): void
  • Parameters

    • maxListenersWarningThreshold: number

    Returns void

subscribe

  • subscribe(): Promise<string>
  • Returns Promise<string>

unsubscribe

  • unsubscribe(): Promise<void>
  • Returns Promise<void>