@secondlayer/sdk 6.22.0 → 6.23.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @secondlayer/sdk
2
2
 
3
- TypeScript SDK for the Second Layer API.
3
+ TypeScript SDK for the Secondlayer API.
4
4
 
5
5
  ## Install
6
6
 
@@ -36,12 +36,19 @@ plan's tier.
36
36
 
37
37
  ## Mental model
38
38
 
39
- - `sl.streams` reads raw ordered chain events from Stacks Streams.
40
- - `sl.index` reads the decoded layer from Stacks Index — FT/NFT transfers, all event types (`events`), and `contractCalls`.
41
- - `sl.contracts` finds deployed contracts by trait (SIP-009/010/013).
42
- - `sl.subgraphs` reads app-specific tables from Stacks Subgraphs.
39
+ Everything is indexing the question is how much of the indexer you run:
43
40
 
44
- ## Stacks Streams
41
+ - `sl.index` — decoded rows we keep indexed: query FT/NFT transfers, all event
42
+ types (`events`), and `contractCalls` — or build your own app index on them
43
+ with the checkpointed `consume()` loop (automatic reorg rewind), `walk()`
44
+ sweeps, and resumable cursors on every page.
45
+ - `sl.subgraphs` — deploy your own indexer (one `defineSubgraph()` file via the
46
+ CLI), then read your hosted tables here. We run the loop.
47
+ - `sl.streams` — the raw ordered event firehose Index itself is built on, with
48
+ a checkpointed `consume()` and dumps `replay()` for building from zero.
49
+ - `sl.contracts` — find deployed contracts by trait (SIP-009/010/013).
50
+
51
+ ## Streams
45
52
 
46
53
  Typed HTTP client for the raw event firehose. Reads require a bearer token (`apiKey`).
47
54
 
@@ -217,7 +224,7 @@ the decoder. Decoders throw when the event type or payload is malformed. Add new
217
224
  helpers beside `src/streams/ft-transfer.ts` and export them through
218
225
  `src/streams/index.ts`.
219
226
 
220
- ## Stacks Index
227
+ ## Index
221
228
 
222
229
  Decoded transfer events.
223
230
 
@@ -245,9 +252,33 @@ for await (const transfer of sl.index.ftTransfers.walk({
245
252
  }
246
253
  ```
247
254
 
255
+ Checkpointed consumer — build your app index.
256
+
257
+ `index.events.consume` / `index.contractCalls.consume` is the same contract as
258
+ the Streams consumer: write your rows inside `onBatch`, return the cursor you
259
+ committed, and reorgs rewind automatically to the fork point. `finalizedOnly`
260
+ holds delivery to rows at or below `tip.finalized_height` (Index rows carry no
261
+ per-event flag). Full runnable example: `examples/sales-index/`.
262
+
263
+ ```typescript
264
+ await sl.index.contractCalls.consume({
265
+ contractId: "SP...marketplace-v4",
266
+ functionName: "purchase-asset",
267
+ fromCursor: await loadCheckpoint(), // null on first run
268
+ fromHeight: 0, // first run: backfill from genesis
269
+ onBatch: async (calls, envelope, ctx) => {
270
+ await commitRowsAndCheckpoint(calls, ctx.cursor);
271
+ return ctx.cursor;
272
+ },
273
+ onReorg: async (reorg) => {
274
+ await rollbackAboveHeight(reorg.fork_point_height);
275
+ },
276
+ });
277
+ ```
278
+
248
279
  ## Transaction-inclusion proofs
249
280
 
250
- Verify — **without trusting Second Layer** — that a transaction is included in a
281
+ Verify — **without trusting Secondlayer** — that a transaction is included in a
251
282
  Stacks (Nakamoto) block, and that ≥70% of the reward cycle's signer weight
252
283
  attested to that block. `verifyTransactionProof` recomputes everything
253
284
  client-side and trusts nothing the API returned.
@@ -314,7 +345,7 @@ fetchRewardSet(opts: {
314
345
 
315
346
  Exported types: `TransactionProof`, `TransactionProofVerifyResult`, `RewardSet`.
316
347
 
317
- ## Stacks Subgraphs
348
+ ## Subgraphs
318
349
 
319
350
  Deploy and query app-specific tables.
320
351