Arbitrum RPC
How to use it
// yarn add @tatumio/tatum
import { TatumSDK, ArbitrumOne, Network } from '@tatumio/tatum'
const tatum = await TatumSDK.init<ArbitrumOne>({ network: Network.ARBITRUM_ONE })
const logs = await tatum.rpc.getLogs({ address: '0xd4d42F0b6DEF4CE0383636770eF773390d85c61A' })
await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
Overview
The eth_getLogs
method is an JSON-RPC method that allows developers to query logs generated by the network, specifically event logs emitted by smart contracts. These logs are an essential part of the ecosystem as they provide a way for developers to monitor contract events and track contract state changes.
This method is particularly useful when building decentralized applications (dApps) that rely on events emitted by smart contracts, as it enables developers to retrieve logs based on specific filter criteria. By using eth_getLogs
, developers can efficiently track and react to events happening on the blockchain.
Parameters
The eth_getLogs
method takes a single input parameter: an object containing the filter criteria. The filter object can have the following fields:
fromBlock
: (optional) The starting block number for the search. Can be a block number or one of the following strings:"earliest"
,"latest"
, or"pending"
.- Example:
"fromBlock": "0x1"
- Example:
toBlock
: (optional) The ending block number for the search. Can be a block number or one of the following strings:"earliest"
,"latest"
, or"pending"
.- Example:
"toBlock": "0x2"
- Example:
address
: (optional) The address or list of addresses of the contracts to filter logs from. Can be a single address or an array of addresses.- Example:
"address": "0xd4d42F0b6DEF4CE0383636770eF773390d85c61A"
- Example:
topics
: (optional) An array of up to four 32-byte topics. Topics are order-dependent, and each topic can be an array of topic hashes ornull
.- Example:
"topics": ["0x123..."]
- Example:
blockhash
: (optional) The block hash to filter logs from. If provided,fromBlock
andtoBlock
are ignored.- Example:
"blockhash": "0xc6ef9..."
- Example:
In addition to the above fields, the transactions
field in the filter object can be specified to include full transaction details instead of just transaction hashes. This is useful when you need more information about the transactions in which the events were emitted.
Return Object
The eth_getLogs
method returns an array of log objects. Each log object contains the following fields:
removed
: A boolean indicating whether the log was removed due to a chain reorganization.- Example:
"removed": false
- Example:
logIndex
: The log index position in the block.- Example:
"logIndex": "0x1"
- Example:
transactionIndex
: The transaction index position in the block.- Example:
"transactionIndex": "0x0"
- Example:
transactionHash
: The hash of the transaction that emitted the log.- Example:
"transactionHash": "0x88eef..."
- Example:
blockHash
: The hash of the block containing the log.- Example:
"blockHash": "0xc6ef9..."
- Example:
blockNumber
: The block number containing the log.- Example:
"blockNumber": "0x1"
- Example:
address
: The address of the contract that emitted the log.- Example:
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
- Example:
data
: The data associated with the log.- Example:
"data":"0x0000000000000000000000000000000000000000000000000000000000000020"
- Example:
topics
: An array of topics (order-dependent) associated with the log.- Example:
"topics": ["0x123..."]
- Example:
JSON-RPC Examples
Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"fromBlock": "0x1",
"toBlock": "0x2",
"address": "0xd4d42F0b6DEF4CE0383636770eF773390d85c61A",
"topics": ["0x123..."]
}
]
}
Response
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"removed": false,
"logIndex": "0x1",
"transactionIndex": "0x0",
"transactionHash": "0x88eef...",
"blockHash": "0xc6ef9...",
"blockNumber": "0x1",
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"data": "0x0000000000000000000000000000000000000000000000000000000000000020",
"topics": ["0x123..."]
}
]
}
This documentation provides a comprehensive overview of the eth_getLogs
JSON-RPC method, its parameters, return objects, and JSON-RPC examples. By using this method, developers can effectively query logs generated by the network and use the retrieved data to track and react to events happening on the blockchain.