logs - EVM Data Stream
Stream raw EVM event logs filtered by contract address and topics. Complete guide on how to use the logs topic in GetBlock EVM Data Stream documentation.
The logs topic sends one notification per matching log from newly mined receipts, in the same shape as eth_getLogs. Filtering works like eth_subscribe("logs"): by emitting contract and by positional topics.
Parameters
filters.address
string or array
No
Emitting contract address, or an array of addresses to match any of.
filters.topics
array
No
Geth-style positional topic filter. Each position is an exact 32-byte hash, an array of hashes (OR), or null (wildcard).
How filters.topics matches, position by position:
[] or omitted
Any log
["0xA"]
topic0 is 0xA
[null, "0xB"]
Anything in topic0, and topic1 is 0xB
[["0xA", "0xC"], null, "0xD"]
topic0 is 0xA or 0xC, and topic2 is 0xD
Topic values are 32 bytes. To match an address in an indexed parameter, left-pad it with zeros: 0x000000000000000000000000 + the 20-byte address.
Request Example
# WebSocket-only. Connect first:
wscat -c 'wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream' -H 'Authorization: Bearer <API-KEY>'
# Then send:
{"jsonrpc":"2.0","id":1,"method":"getblock_subscribe","params":[{"topic":"logs","filters":{"address":"0xdAC17F958D2ee523a2206206994597C13D831ec7","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}}]}// npm install ws
import WebSocket from 'ws';
const ws = new WebSocket('wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream', {
headers: { Authorization: 'Bearer <API-KEY>' }
});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getblock_subscribe',
params: [{
topic: 'logs',
filters: {
address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
]
}
}]
}));
});
ws.on('message', (raw) => {
const msg = JSON.parse(raw);
// First reply is the subscription ID (or an error)
if (msg.id !== undefined) {
console.log(msg.error ?? `Subscribed: ${msg.result}`);
return;
}
const { removed, data } = msg.params.result;
console.log(removed ? 'REMOVED' : 'log', data.address, data.topics[0], data.transactionHash);
});Response Example
The first reply is the subscription ID:
Every later message is an event notification:
Response Parameters
The result object contains the event envelope and the payload in data.
eventId
string
Stable event identifier. A reorg correction reuses it.
removed
boolean
true when a reorg removed this previously delivered event.
revision
number
Event version. For one eventId, a greater revision is newer.
data
object
The log, in the same shape as an eth_getLogs entry.
data.topics
array
Indexed topics. topics[0] is the event signature hash, except for anonymous events.
data.data
string
ABI-encoded non-indexed event arguments.
data.address
string
Address of the contract that emitted the log.
data.blockNumber
string
Block number, hex-encoded.
data.blockHash
string
Hash of the block that contains the log.
data.blockTimestamp
string
Block timestamp in Unix seconds, hex-encoded.
data.transactionHash
string
Hash of the transaction that emitted the log.
data.transactionIndex
string
Transaction's position in the block, hex-encoded.
data.logIndex
string
Log's position in the block, hex-encoded.
data.removed
boolean
The underlying log's removed flag. Use the envelope's removed for reorg handling.
To get named, decoded arguments instead of raw topics and data, use decodedLogs.
Use Cases
Following any contract event, such as swaps, deposits, liquidations, or governance votes
Porting an existing
eth_subscribe("logs")oreth_getLogspolling integrationDecoding events yourself with a full ABI and your own library
Watching a known event across many contracts by filtering on
topic0only
Error Handling
-32602
invalid logs filter: invalid address "…"
filters.address is not a 20-byte hex address.
-32602
invalid logs request: json: unknown field "…"
The request has a field this topic does not accept.
-32001
subscription limit exceeded
You already have 15 active or pending subscriptions.
Last updated
Was this helpful?