@secondlayer/sdk 6.54.0 → 7.0.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/README.md CHANGED
@@ -14,25 +14,14 @@ bun add @secondlayer/sdk
14
14
  import { SecondLayer } from "@secondlayer/sdk";
15
15
 
16
16
  const sl = new SecondLayer({
17
- apiKey: "sk-sl_...", // or `sl login` session token
18
- baseUrl: "https://api.secondlayer.tools", // default
17
+ apiKey: process.env.INSTANCE_TOKEN, // from secondlayer init; omit on loopback
18
+ // default baseUrl: http://127.0.0.1:3800 (or SL_API_URL)
19
19
  });
20
20
  ```
21
21
 
22
- `sl.contracts`, `sl.index`, and `sl.subgraphs` reads are anonymous
23
- — no key needed (`sl.index` rejects free-tier keys — Build+ for keyed access).
24
- **`sl.streams` reads require a bearer token** (`apiKey`) and resolve a per-tier tenant; a
25
- publicly-known free-tier token exists but a bearer is always required. Writes
26
- require an `sk-sl_` API key, created in the platform console at
27
- https://secondlayer.tools/platform/api-keys. (Public Streams bulk dumps —
28
- `client.dumps`, `events.replay` — need no key.)
29
-
30
- **API keys.** Each `sk-sl_` key has a `product`. An **`account`** key (dashboard
31
- default) grants both `streams:read` and `index:read` and is the only key that can
32
- mint new keys; **`streams`** / **`index`** keys are scoped, read-only, and cannot
33
- mint. Mint scoped keys programmatically with `sl.apiKeys.create({ product })`
34
- (needs an account/owner key) — the returned `key` is shown once and inherits your
35
- plan's tier.
22
+ Reads hit your instance. Writes use `INSTANCE_TOKEN` from `secondlayer init` when the
23
+ API is bound beyond loopback. Public archive dumps (`client.dumps`) need no
24
+ instance key.
36
25
 
37
26
  ## Mental model
38
27
 
@@ -43,14 +32,14 @@ Everything is indexing — the question is how much of the indexer you run:
43
32
  with the checkpointed `consume()` loop (automatic reorg rewind), `walk()`
44
33
  sweeps, and resumable cursors on every page.
45
34
  - `sl.subgraphs` — deploy your own indexer (one `defineSubgraph()` file via the
46
- CLI), then read your hosted tables here. We run the loop.
35
+ CLI), then read the tables on this instance.
47
36
  - `sl.streams` — the raw ordered event firehose Index itself is built on, with
48
37
  a checkpointed `consume()` and dumps `replay()` for building from zero.
49
38
  - `sl.contracts` — find deployed contracts by trait (SIP-009/010/013).
50
39
 
51
40
  ## Streams
52
41
 
53
- Typed HTTP client for the raw event firehose. Reads require a bearer token (`apiKey`).
42
+ Typed HTTP client for the raw event firehose. Loopback reads need no key.
54
43
 
55
44
  ```typescript
56
45
  const tip = await sl.streams.tip();
@@ -73,7 +62,7 @@ console.log({ tip, firstCursor: page.events[0]?.cursor });
73
62
  import { createStreamsClient } from "@secondlayer/sdk";
74
63
 
75
64
  const streams = createStreamsClient({
76
- apiKey: process.env.SL_API_KEY!, // sk-sl_... — required for reads
65
+ // apiKey: process.env.INSTANCE_TOKEN, // when the API is bound beyond loopback
77
66
  // verify: true, // verify ed25519 X-Signature on every read
78
67
  // // (auto-fetches the public key; { publicKey } pins a PEM)
79
68
  // dumpsBaseUrl: process.env.SL_STREAMS_DUMPS_URL, // required to use client.dumps
@@ -289,7 +278,7 @@ client-side and trusts nothing the API returned.
289
278
  import { verifyTransactionProof, fetchRewardSet } from "@secondlayer/sdk";
290
279
 
291
280
  const proof = await fetch(
292
- `https://api.secondlayer.tools/v1/index/transactions/${txid}/proof`,
281
+ `http://127.0.0.1:3800/v1/index/transactions/${txid}/proof`,
293
282
  ).then((r) => r.json());
294
283
 
295
284
  const result = verifyTransactionProof(proof); // anchored + consensus (embedded set)
@@ -531,8 +520,8 @@ few hundredths of a cent per request from a Stacks wallet. Payment is **gasless*
531
520
  (you sign; we sponsor the STX fee) and uses standard **x402 v2** on `stacks:1`.
532
521
  Supported assets: **sBTC** (default), **USDCx**, **STX**.
533
522
 
534
- > Keyed (`sk-sl_`) requests bypass x402 and bill through your plan — x402 is for
535
- > accountless callers.
523
+ > Keyed (`INSTANCE_TOKEN`) requests skip x402. The rail is for accountless
524
+ > callers on an instance that has it enabled.
536
525
 
537
526
  Drop-in `fetch` that pays on `402` automatically:
538
527
 
@@ -547,7 +536,7 @@ const x402fetch = withX402(fetch, {
547
536
  });
548
537
 
549
538
  const res = await x402fetch(
550
- "https://api.secondlayer.tools/v1/index/events?event_type=ft_transfer",
539
+ "http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer",
551
540
  );
552
541
  const data = await res.json();
553
542
  readX402Receipt(res); // { success, txid, payer, network } | null
@@ -558,7 +547,7 @@ Or a small client returning `{ data, payment }`:
558
547
  ```typescript
559
548
  import { createX402Client } from "@secondlayer/sdk";
560
549
 
561
- const sl = createX402Client({ account, baseUrl: "https://api.secondlayer.tools" });
550
+ const sl = createX402Client({ account }); // baseUrl defaults to http://127.0.0.1:3800
562
551
  const { data, payment } = await sl.get("/v1/index/events", {
563
552
  query: { event_type: "ft_transfer" },
564
553
  });