Register and show off your project at Ethereum QuickPitch and win $10,000. Apply now

Contents

eth-v1-events RPC method

Provides endpoint to subscribe to beacon node Server-Sent-Events stream. Consumers should use eventsource implementation to listen on those events. Servers may send SSE comments beginning with : for any purpose, including to keep the event stream connection alive in the presence of proxy servers.

Parameters:

  1. topics - array[string] - (Required) Event types to subscribe to. Available values: head, block, attestation, voluntary_exit, finalized_checkpoint, chain_reorg, contribution_and_proof.

Returns:

  1. data - object - with the following values:

    slot - string

    block - string

    state - string

    current_duty_dependent_root - string

    previous_duty_dependent_root - string

    epoch_transition - boolean

    execution_optimistic - boolean

Code Examples:

const EventSource = require("eventsource");

let url = "http://sample-endpoint-name.network.quiknode.pro/token-goes-here/eth/v1/events?topics=head"
let eventSourceInitDict = {headers: {'Accept': 'text/event-stream'}};

async function main() {
  let es = new EventSource(url, eventSourceInitDict);

  es.addEventListener('head', function (e) {
      console.log(e.data)
  })
}

main();
Ready to get started? Create a free account