Fantom RPC
How to use it
// yarn add @tatumio/tatum
import { TatumSDK, Fantom, Network } from '@tatumio/tatum'
const tatum = await TatumSDK.init<Fantom>({ network: Network.FANTOM })
const logs = await tatum.rpc.getLogs({ address: '0x82487dF5b4cF19DB597A092c8103759466Be9e5a' })
await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
Overview
The eth_getLogs
method is an 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": "0x82487dF5b4cF19DB597A092c8103759466Be9e5a"
- 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": "0x82487dF5b4cF19DB597A092c8103759466Be9e5a"
- 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": "0x82487dF5b4cF19DB597A092c8103759466Be9e5a",
"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
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.