eth_getLogs - Base
Example code for the eth_getLogs JSON-RPC method. Complete guide on how to use eth_getLogs JSON-RPC in GetBlock Web3 documentation.
Parameters
Parameter
Type
Required
Description
Filter Object
Field
Type
Required
Description
Request
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{
"fromBlock": "0x12d6800",
"toBlock": "0x12d6900",
"address": "0x4200000000000000000000000000000000000006",
"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
}],
"id": "getblock.io"
}'const axios = require('axios');
// Query ERC-20 Transfer events
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'eth_getLogs',
params: [{
fromBlock: '0x12d6800',
toBlock: '0x12d6900',
address: '0x4200000000000000000000000000000000000006', // WETH
topics: [transferTopic]
}],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
const logs = response.data.result;
console.log('Found', logs.length, 'transfer events');
logs.forEach(log => {
console.log('Block:', parseInt(log.blockNumber, 16));
console.log('Tx:', log.transactionHash);
});Response
Response Parameters
Parameter
Type
Description
Use Cases
Error Handling
Error Code
Message
Description
Web3 Integration
Previouseth_getTransactionByBlockHashAndIndex - BaseNexteth_getTransactionByBlockNumberAndIndex - Base
Last updated
Was this helpful?