ethOnBlock
Name: ethOnBlock
ethOnBlock is a stream of changes in the EVM state when a new block is mined. The stream includes the results of eth_call and other RPC requests provided by users and is restricted based on the number of calls.
This is a Gateway-API only stream.
Options
Key
Description
Values
include
Fields to include in the on block event stream
name, response, blockHeight, tag
[Default: all]
call-params
Fields used to build an RPC call request
method- see chart below for available methods and additional fields required for each method
tag- latest, 0, or negative number. [Default: 0]
name- unique string identifier for call. [Default: integer counter]
Method
Call Documentation
Additional Fields
Examples - Websocket
Subscribing to the ethOnBlock stream via the Gateway-API in Python (Line 6 creates the subscription):
import asyncio, jason, websockets
async def main():
async with websockets.connect(ws_uri) as websocket:
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "subscribe",
"params": [
"ethOnBlock",
{
"include": ["name", "response", "block_height", "tag"],
"call-params": [
{
"name": "my_call_name",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"value": "0x9184e72a",
"data": "0x00"
},
{
"name": "number",
"method": "eth_blockNumber"
}
]
}
]
}
await websocket.send(json.dumps(payload))
subscription_id = await websocket.recv()
while True:
next_notification = await websocket.recv()
print(next_notification) # or process it generally
await websocket.send(json.dumps({"jsonrpc": "2.0", "id": 2, "method": "unsubscribe", "params": [subscription_id]}))
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())The ethOnBlock stream is not available via Cloud-API.
TaskCompletedEventis received after all calls have been executed upon receipt of a block.TaskDisabledEvent is received if there is an error response to a call, indicating that the call has been disabled.
Python Gateway:
Go Gateway:
Examples - gRPC
Subscribing to Gateway ethOnBlock Stream in Go using gRPC.
Response (ethOnBlock Event)
TaskCompletedEventis received after all calls have been executed upon receipt of a block.TaskDisabledEvent is received if there is an error response to a call, indicating that the call has been disabled.