eth_getLogs - Cronos RPC Method
Query event logs on Cronos. Essential for indexing DeFi protocols, NFT marketplaces, and Crypto.com ecosystem integrations on the EVM-compatible Crypto.com blockchain.
Returns an array of all logs matching a given filter object on Cronos.
Why Cronos? Build on the EVM-compatible Crypto.com blockchain with fast finality and deep Crypto.com ecosystem integration.
When to Use This Method
The eth_getLogs method serves these key scenarios for Cronos developers building DeFi and payment applications:
- Index smart contract events - Track transfers, swaps, and approvals emitted by any contract on Cronos for use in indexed databases
- Monitor DeFi protocol activity - Watch for liquidity changes, price updates, and position events in real time across DeFi protocols, NFT marketplaces, and Crypto.com ecosystem integrations
- Build analytics pipelines - Extract on-chain event data for dashboards, reporting, and trend analysis on Cronos
- Track token holder activity - Monitor whale movements and large transfers to detect significant market activity
Common Use Cases
1. Monitor ERC20 Transfer Events
Track all transfer events for a specific token contract within a defined block range. The Transfer event signature hash filters for exactly this event type, and you can optionally filter by sender or recipient address using indexed topics.
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://api-cronos-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
const tokenAddress = '0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23';
const transferTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
async function getRecentTransfers(fromBlock, toBlock) {
const logs = await provider.getLogs({
address: tokenAddress,
fromBlock: fromBlock,
toBlock: toBlock,
topics: [transferTopic]
});
const transfers = logs.map(log => ({
from: '0x' + log.topics[1].slice(26),
to: '0x' + log.topics[2].slice(26),
amount: BigInt(log.data).toString(),
txHash: log.transactionHash
}));
console.log(`Found ${transfers.length} transfers`);
return transfers;
}
const recentTransfers = await getRecentTransfers('latest', 'latest');2. Track DEX Swap Events
Capture swap events from a DEX to analyze trading volume, price impact, and liquidity flow. Each swap emits event parameters that include the amounts and addresses involved - ideal for building price feeds and volume aggregators.
const provider = new JsonRpcProvider('https://api-cronos-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
const SWAP_TOPIC = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822';
const pairAddress = '0x5C7F8A570d578ED84E63fdFA7b1eE72dEae1AE23';
async function getRecentSwaps(fromBlock, toBlock) {
const logs = await provider.getLogs({
address: pairAddress,
fromBlock: fromBlock,
toBlock: toBlock,
topics: [SWAP_TOPIC]
});
return logs.map(log => ({
sender: '0x' + log.topics[1].slice(26),
to: '0x' + log.topics[2].slice(26),
amount0In: BigInt('0x' + log.data.slice(2, 66)).toString(),
amount1In: BigInt('0x' + log.data.slice(66, 130)).toString(),
amount0Out: BigInt('0x' + log.data.slice(130, 194)).toString(),
amount1Out: BigInt('0x' + log.data.slice(194, 258)).toString(),
txHash: log.transactionHash
}));
}
const swaps = await getRecentSwaps('latest', 'latest');
console.log(`Found ${swaps.length} swaps`);3. Multi-Contract Event Aggregation
Query events from multiple contracts simultaneously by passing an array of addresses. This is useful for cross-protocol analytics - aggregating lending, borrowing, and liquidation events from multiple DeFi protocols in a single query on Cronos.
const provider = new JsonRpcProvider('https://api-cronos-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
const contracts = [
'0xContractA...',
'0xContractB...',
'0xContractC...'
];
const EVENT_TOPIC = '0x...';
async function aggregateEvents(fromBlock, toBlock) {
const logs = await provider.getLogs({
address: contracts,
fromBlock: fromBlock,
toBlock: toBlock,
topics: [EVENT_TOPIC]
});
const grouped = {};
for (const log of logs) {
const contract = log.address;
if (!grouped[contract]) grouped[contract] = [];
grouped[contract].push(log);
}
for (const [contract, events] of Object.entries(grouped)) {
console.log(`${contract}: ${events.length} events`);
}
return grouped;
}
aggregateEvents('0x100000', '0x100500');Cronos Rate Limits
Block Range Limit
On Cronos, eth_getLogs queries are subject to a maximum block range of 500 blocks. This means the difference between fromBlock and toBlock cannot exceed 500 blocks per request.
Additionally, each query can return a maximum of 10,000 log entries.
For querying larger block ranges, split your requests into smaller batches:
// Example: Query in 500-block batches
const BATCH_SIZE = 500;
let fromBlock = startBlock;
while (fromBlock <= endBlock) {
const toBlock = Math.min(fromBlock + BATCH_SIZE - 1, endBlock);
const logs = await provider.getLogs({ fromBlock, toBlock, ...filter });
// Process logs
fromBlock = toBlock + 1;
}Best Practices
- Limit block range to 1,000-5,000 blocks per query to avoid timeouts and rate limits on Cronos
- Use topic filters for efficient log filtering: the node filters at the storage level before returning results
- For high-volume monitoring, use
eth_newFilterwith polling instead of repeatedly callingeth_getLogs - Store the last processed block number for incremental indexing rather than re-scanning the full chain
- Be aware that
eth_getLogsoften has stricter rate limits than other RPC methods on Cronos
Code Examples
Error Handling
| Error Code | Message | Description |
|---|---|---|
| -32005 | Query returned more than 10000 results | Reduce block range |
| -32602 | Invalid params | Invalid filter parameters |
Related Methods
eth_newFilter- Create a filter for logseth_getFilterChanges- Poll filter for new logs
eth_call
Execute smart contract calls without creating transactions on Cronos. Essential for reading contract state for DeFi protocols, NFT marketplaces, and Crypto.com ecosystem integrations.
eth_newFilter
Create an event log filter on Cronos. Essential for event monitoring, contract activity tracking, and DeFi event streaming for DeFi protocols, NFT marketplaces, and Crypto.com ecosystem integrations.