effective-indexer 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +185 -0
- package/dist/index.cjs +961 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +294 -0
- package/dist/index.d.ts +294 -0
- package/dist/index.js +940 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksandr Shenshin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Effective Indexer
|
|
2
|
+
|
|
3
|
+
Lightweight EVM smart contract event indexer built with [Effect](https://effect.website).
|
|
4
|
+
|
|
5
|
+
Indexes smart contract events into SQLite with:
|
|
6
|
+
- Historical backfill (`eth_getLogs` in chunks)
|
|
7
|
+
- Live polling for new blocks
|
|
8
|
+
- Checkpoint resume after restart
|
|
9
|
+
- Reorg detection and rollback
|
|
10
|
+
|
|
11
|
+
Works with any EVM-compatible chain (Ethereum, Rootstock, Polygon, Arbitrum, etc.).
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Node.js `>=20`
|
|
16
|
+
- RPC endpoint with `eth_getLogs` support
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install effective-indexer effect
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`effect` is a peer dependency.
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { Indexer } from "effective-indexer"
|
|
30
|
+
import type { Abi } from "viem"
|
|
31
|
+
|
|
32
|
+
const abi: Abi = [
|
|
33
|
+
{
|
|
34
|
+
type: "event",
|
|
35
|
+
name: "Transfer",
|
|
36
|
+
inputs: [
|
|
37
|
+
{ indexed: true, name: "from", type: "address" },
|
|
38
|
+
{ indexed: true, name: "to", type: "address" },
|
|
39
|
+
{ indexed: false, name: "value", type: "uint256" },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const indexer = Indexer.create({
|
|
45
|
+
rpcUrl: "https://eth.llamarpc.com",
|
|
46
|
+
dbPath: "./data/events.db",
|
|
47
|
+
contracts: [
|
|
48
|
+
{
|
|
49
|
+
name: "USDT",
|
|
50
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
51
|
+
abi,
|
|
52
|
+
events: ["Transfer"],
|
|
53
|
+
startBlock: 19000000n,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
network: {
|
|
57
|
+
polling: { intervalMs: 12000, confirmations: 2 },
|
|
58
|
+
logs: { chunkSize: 2000 },
|
|
59
|
+
reorg: { depth: 64 },
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await indexer.start() // non-blocking, runs in background
|
|
64
|
+
|
|
65
|
+
const events = await indexer.query({
|
|
66
|
+
contractName: "USDT",
|
|
67
|
+
eventName: "Transfer",
|
|
68
|
+
limit: 50,
|
|
69
|
+
order: "desc",
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
console.log(events.length)
|
|
73
|
+
|
|
74
|
+
// later
|
|
75
|
+
await indexer.stop()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
### `Indexer.create(config)`
|
|
81
|
+
|
|
82
|
+
Returns `IndexerHandle`:
|
|
83
|
+
- `start(): Promise<void>` start indexing loop (non-blocking)
|
|
84
|
+
- `stop(): Promise<void>` stop and dispose runtime
|
|
85
|
+
- `query(q?: EventQuery): Promise<ParsedEvent[]>`
|
|
86
|
+
- `count(q?: EventQuery): Promise<number>`
|
|
87
|
+
|
|
88
|
+
### `IndexerConfig`
|
|
89
|
+
|
|
90
|
+
| Field | Type | Default | Description |
|
|
91
|
+
|-------|------|---------|-------------|
|
|
92
|
+
| `rpcUrl` | `string` | — | RPC endpoint URL |
|
|
93
|
+
| `dbPath` | `string` | `"./indexer.db"` | SQLite database path |
|
|
94
|
+
| `contracts` | `ContractConfig[]` | — | Contracts to index |
|
|
95
|
+
| `network` | `NetworkConfig` | see below | Network tuning |
|
|
96
|
+
| `logLevel` | `string` | `"info"` | Minimum log level |
|
|
97
|
+
| `logFormat` | `string` | `"pretty"` | Log output format |
|
|
98
|
+
| `enableTelemetry` | `boolean` | `true` | Set `false` for errors-only |
|
|
99
|
+
|
|
100
|
+
### `NetworkConfig`
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
{
|
|
104
|
+
polling: {
|
|
105
|
+
intervalMs: 12000, // block polling interval
|
|
106
|
+
confirmations: 1, // blocks behind head to consider confirmed
|
|
107
|
+
},
|
|
108
|
+
logs: {
|
|
109
|
+
chunkSize: 5000, // blocks per eth_getLogs request
|
|
110
|
+
maxRetries: 5, // retry count on RPC failure
|
|
111
|
+
retry: {
|
|
112
|
+
baseDelayMs: 1000, // initial retry delay
|
|
113
|
+
maxDelayMs: 30000, // cap for exponential backoff
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
reorg: {
|
|
117
|
+
depth: 20, // block hash buffer depth for reorg detection
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
All fields are optional — defaults are shown above.
|
|
123
|
+
|
|
124
|
+
### Network Tuning Profiles
|
|
125
|
+
|
|
126
|
+
| Chain | `polling.intervalMs` | `polling.confirmations` | `logs.chunkSize` | `reorg.depth` |
|
|
127
|
+
|-------|---------------------|------------------------|------------------|---------------|
|
|
128
|
+
| Ethereum | 12000 | 2 | 2000 | 64 |
|
|
129
|
+
| Rootstock | 30000 | 1 | 5000 | 20 |
|
|
130
|
+
| Polygon | 2000 | 32 | 2000 | 128 |
|
|
131
|
+
| Arbitrum | 1000 | 0 | 5000 | 1 |
|
|
132
|
+
|
|
133
|
+
### `EventQuery`
|
|
134
|
+
|
|
135
|
+
- `contractName?: string`
|
|
136
|
+
- `eventName?: string`
|
|
137
|
+
- `fromBlock?: bigint`
|
|
138
|
+
- `toBlock?: bigint`
|
|
139
|
+
- `txHash?: string`
|
|
140
|
+
- `limit?: number`
|
|
141
|
+
- `offset?: number`
|
|
142
|
+
- `order?: "asc" | "desc"`
|
|
143
|
+
|
|
144
|
+
## Telemetry & Logging
|
|
145
|
+
|
|
146
|
+
The indexer uses Effect's native logging system. All log output is controlled via config — no `console.log` calls in source.
|
|
147
|
+
|
|
148
|
+
| Level | What's emitted |
|
|
149
|
+
|-------|---------------|
|
|
150
|
+
| `error` | Indexer errors (RPC failures, storage errors) |
|
|
151
|
+
| `warning` | Reorg detection, parent hash mismatches |
|
|
152
|
+
| `info` | Indexer start/stop, backfill start/complete, reorg handled |
|
|
153
|
+
| `debug` | Chunk indexed, block indexed, storage init, query/count execution, reorg rollback, BlockCursor init |
|
|
154
|
+
| `trace` | Individual log fetches, block emissions, no-new-blocks polls |
|
|
155
|
+
|
|
156
|
+
### Recommendations
|
|
157
|
+
|
|
158
|
+
- **Production**: `logLevel: "info"` — lifecycle events and warnings
|
|
159
|
+
- **Troubleshooting**: `logLevel: "debug"` — per-chunk/block detail
|
|
160
|
+
- **Deep inspection**: `logLevel: "trace"` — every RPC call and poll
|
|
161
|
+
- **Silent**: `enableTelemetry: false` — only errors
|
|
162
|
+
|
|
163
|
+
## Operational Notes
|
|
164
|
+
|
|
165
|
+
- Use one writer process per SQLite database file.
|
|
166
|
+
- Keep database file on persistent storage.
|
|
167
|
+
- On restart, the indexer resumes from checkpoint and backfills missed blocks.
|
|
168
|
+
- If RPC does not support `eth_getLogs`, indexing cannot work.
|
|
169
|
+
|
|
170
|
+
## Development
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
npm run build
|
|
174
|
+
npm run typecheck
|
|
175
|
+
npm run test
|
|
176
|
+
npm run check
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Live Integration Tests
|
|
180
|
+
|
|
181
|
+
Integration tests read RPC URLs from `.env` (mainnet) and `.env.test` (testnet) using `EVM_RPC_URL`.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm run test:integration
|
|
185
|
+
```
|