| description | Subscribe to different Ethereum event types like newHeads, logs, pendingTransactions, and minedTransactions using WebSockets. |
|---|
- Event types- specifies the type of event to listen to (ex: new pending transactions, logs, etc.)
- Optional params - optional parameters to include to describe the type of event to listen to (ex:
address)
While the subscription is active, you will receive events formatted as an object described below:
- Event Object:
jsonrpc: Always "2.0"method: Always "eth_subscription"params: An object with the following fields:subscription: The subscription ID returned by theeth_subscribecall which created this subscription. This ID will be attached to all received events and can also be used to cancel the subscription usingeth_unsubscriberesult: An object whose contents vary depending on the event type.
{% code overflow="wrap" %}
// initiate websocket stream
wscat -c wss://0g-galileo.blockpi.network/v1/ws/<your-api-key>
//create an event
{"jsonrpc":"2.0","id": 2, "method": "eth_subscribe", "params": ["newHeads"]}
// Result
{...}{% endcode %}