-
Import the Module: Import
getLogs_ext.js
into your application:import { SeiLogsFetcher } from './getLogs_ext.js'; // Adjust the path if needed
-
Replace Direct Calls to
sei_getLogs
: Replace any direct calls to the Ethereum node'ssei_getLogs
method with an instance ofSeiLogsFetcher
:const fetcher = new SeiLogsFetcher("http://localhost:8545"); const logs = await fetcher.getLogs(filter, "INFO");
-
Ensure Filter Compatibility: If using frameworks like ethers.js, ensure the filter object passed to
getLogs
is compatible with thesei_getLogs
method format. No additional adjustments are required for seamless integration. -
Abstract Network Limitations: Use
SeiLogsFetcher
as a transparent solution to handlesei_getLogs
block and log limits. Internally, it manages batching, splitting, and aggregation, presenting a unified and complete response to your application.
import { SeiLogsFetcher } from './getLogs_ext.js';
(async () => {
const providerUrl = "http://localhost:8545";
const fetcher = new SeiLogsFetcher(providerUrl);
const filter = {
fromBlock: 107432958,
toBlock: 107433958,
address: "0xe8eae1aaB1b4BBa29eAbaEfe7df4510833b6491e",
topics: [], // Add topics if needed
};
try {
const logs = await fetcher.getLogs(filter, "INFO");
console.log("Aggregated logs:", logs);
} catch (error) {
console.error("Failed to fetch logs:", error);
}
})();
SeiLogsFetcher
can preprocess log-fetching requests in Express.js:
import express from "express";
import { SeiLogsFetcher } from "./getLogs_ext.js"; // Adjust the path as needed
const app = express();
const PORT = 3000;
// Initialize the SeiLogsFetcher
const providerUrl = "http://localhost:8545";
const fetcher = new SeiLogsFetcher(providerUrl);
// Middleware to handle log-fetching requests
app.use(express.json()); // Parse incoming JSON requests
app.post("/getLogs", async (req, res) => {
const { filter, logLevel = "INFO" } = req.body; // Expect filter and log level in the request body
try {
const logs = await fetcher.getLogs(filter, logLevel);
res.json({
success: true,
logs,
});
} catch (error) {
console.error(`Failed to fetch logs: ${error.message}`);
res.status(500).json({
success: false,
error: error.message,
});
}
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
-
INFO Mode:
- Logs essential information (batch range, log counts) to the console.
- Provides a clean, aggregated response, ideal for production use.
-
DEBUG Mode:
- Outputs detailed logs, including batch ranges, splitting decisions, and responses, to the console only.
- The returned response remains clean and consistent, unaffected by the debug output.