@valve-tech/trueblocks-sdk 0.0.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +140 -0
  4. package/dist/client.d.ts +25 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +35 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/errors.d.ts +22 -0
  9. package/dist/errors.d.ts.map +1 -0
  10. package/dist/errors.js +26 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/generated.d.ts +3686 -0
  13. package/dist/generated.d.ts.map +1 -0
  14. package/dist/generated.js +10 -0
  15. package/dist/generated.js.map +1 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +4 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/variants/blocks.d.ts +65 -0
  21. package/dist/variants/blocks.d.ts.map +1 -0
  22. package/dist/variants/blocks.js +24 -0
  23. package/dist/variants/blocks.js.map +1 -0
  24. package/dist/variants/chunks.d.ts +47 -0
  25. package/dist/variants/chunks.d.ts.map +1 -0
  26. package/dist/variants/chunks.js +18 -0
  27. package/dist/variants/chunks.js.map +1 -0
  28. package/dist/variants/export.d.ts +51 -0
  29. package/dist/variants/export.d.ts.map +1 -0
  30. package/dist/variants/export.js +25 -0
  31. package/dist/variants/export.js.map +1 -0
  32. package/dist/variants/slurp.d.ts +21 -0
  33. package/dist/variants/slurp.d.ts.map +1 -0
  34. package/dist/variants/slurp.js +13 -0
  35. package/dist/variants/slurp.js.map +1 -0
  36. package/dist/variants/state.d.ts +27 -0
  37. package/dist/variants/state.d.ts.map +1 -0
  38. package/dist/variants/state.js +8 -0
  39. package/dist/variants/state.js.map +1 -0
  40. package/dist/variants/traces.d.ts +19 -0
  41. package/dist/variants/traces.d.ts.map +1 -0
  42. package/dist/variants/traces.js +8 -0
  43. package/dist/variants/traces.js.map +1 -0
  44. package/dist/variants/transactions.d.ts +24 -0
  45. package/dist/variants/transactions.d.ts.map +1 -0
  46. package/dist/variants/transactions.js +10 -0
  47. package/dist/variants/transactions.js.map +1 -0
  48. package/dist/verbs.d.ts +331 -0
  49. package/dist/verbs.d.ts.map +1 -0
  50. package/dist/verbs.js +141 -0
  51. package/dist/verbs.js.map +1 -0
  52. package/package.json +34 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@valve-tech/trueblocks-sdk` are documented in
4
+ this file.
5
+
6
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
7
+ and this project adheres to [Semantic Versioning](https://semver.org/).
8
+
9
+ ## [Unreleased]
10
+
11
+ Experimental package, not yet published. Vertical-slice prototype:
12
+ codegen pipeline + client core + `/status` and `/blocks` verbs with
13
+ 100/100/100/100 coverage on what's implemented.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 valve-tech
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,140 @@
1
+ # `@valve-tech/trueblocks-sdk`
2
+
3
+ Typed TypeScript HTTP client to a running [TrueBlocks](https://trueblocks.io)
4
+ `chifra` daemon. Same verb surface as the upstream Go SDK, delivered
5
+ as `fetch`-based REST calls — no Go runtime, no subprocess spawning,
6
+ browser/mobile safe.
7
+
8
+ Part of the
9
+ [`valve-tech/evm-toolkit`](https://github.com/valve-tech/evm-toolkit)
10
+ monorepo.
11
+
12
+ ## Prerequisite
13
+
14
+ You need a running `chifra daemon` somewhere this client can reach
15
+ over HTTP. That requires installing `trueblocks-core` and indexing
16
+ the chains you care about. **This package does not bundle or invoke
17
+ chifra.** See [TrueBlocks install docs](https://trueblocks.io/docs/install/install-core/).
18
+
19
+ If you can't run chifra, this package isn't for you.
20
+
21
+ ## Install
22
+
23
+ ```sh
24
+ npm install @valve-tech/trueblocks-sdk
25
+ ```
26
+
27
+ No peer dependencies. Uses `globalThis.fetch` (Node 18+, every modern
28
+ browser).
29
+
30
+ ## 30-second quickstart
31
+
32
+ ```ts
33
+ import { createTrueblocksClient } from '@valve-tech/trueblocks-sdk'
34
+
35
+ const client = createTrueblocksClient({
36
+ baseUrl: 'http://localhost:8080',
37
+ })
38
+
39
+ // Daemon status
40
+ const status = await client.status()
41
+ console.log(status)
42
+
43
+ // Block reads
44
+ const blocks = await client.blocks({
45
+ blocks: ['18000000', '18000001'],
46
+ })
47
+ console.log(blocks)
48
+
49
+ // List appearances for an address
50
+ const appearances = await client.list({
51
+ addrs: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045'],
52
+ })
53
+ console.log(appearances)
54
+ ```
55
+
56
+ ## Public surface
57
+
58
+ ### `createTrueblocksClient(options)`
59
+
60
+ ```ts
61
+ interface CreateTrueblocksClientOptions {
62
+ baseUrl: string // e.g. 'http://localhost:8080'
63
+ fetch?: typeof globalThis.fetch // optional override (testing, custom transport)
64
+ }
65
+ ```
66
+
67
+ Returns a `TrueblocksClient` with one method per chifra endpoint
68
+ (flat surface — see [Verbs](#verbs) below).
69
+
70
+ ### Errors
71
+
72
+ Every chifra-side failure throws a `TrueblocksError`:
73
+
74
+ ```ts
75
+ import { TrueblocksError } from '@valve-tech/trueblocks-sdk'
76
+
77
+ try {
78
+ await client.status()
79
+ } catch (err) {
80
+ if (err instanceof TrueblocksError) {
81
+ console.log(err.path) // chifra endpoint that failed (e.g. '/status')
82
+ console.log(err.status) // HTTP status if applicable
83
+ }
84
+ }
85
+ ```
86
+
87
+ ### Verbs
88
+
89
+ Every chifra HTTP endpoint is exposed as a typed method on the
90
+ client. Method names match the chifra CLI verbs.
91
+
92
+ | Group | Method | Endpoint | Variants |
93
+ |---|---|---|---|
94
+ | Accounts | `client.list(...)` | `GET /list` | — |
95
+ | Accounts | `client.export(...)` | `GET /export` | `.appearances` `.receipts` `.logs` `.approvals` `.traces` `.neighbors` `.statements` `.transfers` `.assets` `.balances` `.withdrawals` `.count` |
96
+ | Accounts | `client.monitors(...)` | `GET /monitors` | — |
97
+ | Accounts | `client.names(...)` | `GET /names` | — |
98
+ | Accounts | `client.abis(...)` | `GET /abis` | — |
99
+ | Chain Data | `client.blocks(...)` | `GET /blocks` | `.hashes` `.uncles` `.traces` `.uniq` `.logs` `.withdrawals` `.count` |
100
+ | Chain Data | `client.transactions(...)` | `GET /transactions` | `.traces` `.uniq` `.logs` |
101
+ | Chain Data | `client.receipts(...)` | `GET /receipts` | — |
102
+ | Chain Data | `client.logs(...)` | `GET /logs` | — |
103
+ | Chain Data | `client.traces(...)` | `GET /traces` | `.count` |
104
+ | Chain State | `client.when(...)` | `GET /when` | — |
105
+ | Chain State | `client.state(...)` | `GET /state` | `.call` |
106
+ | Chain State | `client.tokens(...)` | `GET /tokens` | — |
107
+ | Admin | `client.config(...)` | `GET /config` | — |
108
+ | Admin | `client.status(...)` | `GET /status` | — |
109
+ | Admin | `client.chunks(...)` | `GET /chunks` | `.manifest` `.index` `.blooms` `.pins` `.addresses` `.appearances` `.stats` |
110
+ | Admin | `client.init(...)` | `GET /init` | — |
111
+ | Other | `client.slurp(...)` | `GET /slurp` | `.appearances` `.count` |
112
+
113
+ **Base methods** return the OpenAPI polymorphic union — useful when
114
+ flag combinations are constructed at runtime. **Variants** preselect
115
+ a flag (or `mode` enum value, for `chunks`) and narrow the return
116
+ type to the single concrete shape that flag produces. Mirrors the
117
+ Go SDK's `XxxOptions.XxxFlag()` family.
118
+
119
+ Example:
120
+
121
+ ```ts
122
+ // Polymorphic — narrow at the call site:
123
+ const result = await client.blocks({ blocks: ['18000000'], logs: true })
124
+ // result.data is (Block | LightBlock | Log | …)[]
125
+
126
+ // Variant — concrete return type, no narrowing needed:
127
+ const result = await client.blocks.logs({ blocks: ['18000000'] })
128
+ // result.data is Log[]
129
+ ```
130
+
131
+ Per-method query parameters are typed against the upstream OpenAPI
132
+ spec — your editor surfaces the available options via IntelliSense.
133
+
134
+ ## License
135
+
136
+ MIT, in line with the rest of the `@valve-tech/*` toolkit. The
137
+ upstream `trueblocks-core` project is GPL-3.0-or-later, but this
138
+ package is a clean-room TypeScript reimplementation against the
139
+ public OpenAPI spec — no GPL code is incorporated. See the
140
+ `LICENSE` file for full terms.
@@ -0,0 +1,25 @@
1
+ import type { paths } from './generated.js';
2
+ import { type Verbs } from './verbs.js';
3
+ export type FetchFn = typeof globalThis.fetch;
4
+ export interface CreateTrueblocksClientOptions {
5
+ /**
6
+ * Base URL of the chifra daemon, e.g. `'http://localhost:8080'`.
7
+ * A trailing slash is allowed and stripped.
8
+ */
9
+ baseUrl: string;
10
+ /**
11
+ * Optional fetch override. Defaults to `globalThis.fetch`. Useful
12
+ * for tests, custom transports, or environments that need to wrap
13
+ * the fetch call (auth headers, retry, instrumentation).
14
+ */
15
+ fetch?: FetchFn;
16
+ }
17
+ /**
18
+ * Internal request function used by every verb. Verbs are pure
19
+ * factories that take this and return their typed callable — tests
20
+ * inject a mock to exercise verb logic without hitting fetch.
21
+ */
22
+ export type RequestFn = <R>(path: keyof paths, query?: Record<string, unknown>) => Promise<R>;
23
+ export type TrueblocksClient = Verbs;
24
+ export declare function createTrueblocksClient(options: CreateTrueblocksClientOptions): TrueblocksClient;
25
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAEpD,MAAM,MAAM,OAAO,GAAG,OAAO,UAAU,CAAC,KAAK,CAAA;AAE7C,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,KAAK,EACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,CAAC,CAAC,CAAA;AAEf,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAEpC,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,6BAA6B,GACrC,gBAAgB,CAyClB"}
package/dist/client.js ADDED
@@ -0,0 +1,35 @@
1
+ import { TrueblocksError } from './errors.js';
2
+ import { createVerbs } from './verbs.js';
3
+ export function createTrueblocksClient(options) {
4
+ const baseUrl = options.baseUrl.replace(/\/$/, '');
5
+ const fetchFn = options.fetch ?? globalThis.fetch;
6
+ const request = async (path, query) => {
7
+ const url = new URL(baseUrl + path);
8
+ if (query) {
9
+ for (const [key, value] of Object.entries(query)) {
10
+ if (value === undefined || value === null)
11
+ continue;
12
+ if (Array.isArray(value)) {
13
+ for (const item of value)
14
+ url.searchParams.append(key, String(item));
15
+ }
16
+ else {
17
+ url.searchParams.set(key, String(value));
18
+ }
19
+ }
20
+ }
21
+ let response;
22
+ try {
23
+ response = await fetchFn(url.toString());
24
+ }
25
+ catch (err) {
26
+ throw new TrueblocksError(`chifra request to ${path} failed: ${err.message}`, { path: path, cause: err });
27
+ }
28
+ if (!response.ok) {
29
+ throw new TrueblocksError(`chifra ${path} returned ${response.status} ${response.statusText}`, { path: path, status: response.status });
30
+ }
31
+ return response.json();
32
+ };
33
+ return createVerbs(request);
34
+ }
35
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAc,MAAM,YAAY,CAAA;AA8BpD,MAAM,UAAU,sBAAsB,CACpC,OAAsC;IAEtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAClD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;IAEjD,MAAM,OAAO,GAAc,KAAK,EAC9B,IAAiB,EACjB,KAA+B,EACnB,EAAE;QACd,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,GAAI,IAAe,CAAC,CAAA;QAC/C,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;oBAAE,SAAQ;gBACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,KAAK,MAAM,IAAI,IAAI,KAAK;wBAAE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;gBACtE,CAAC;qBAAM,CAAC;oBACN,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;gBAC1C,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,QAAkB,CAAA;QACtB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC1C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,eAAe,CACvB,qBAAqB,IAAc,YAAa,GAAa,CAAC,OAAO,EAAE,EACvE,EAAE,IAAI,EAAE,IAAc,EAAE,KAAK,EAAE,GAAG,EAAE,CACrC,CAAA;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,eAAe,CACvB,UAAU,IAAc,aAAa,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,EAC7E,EAAE,IAAI,EAAE,IAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAClD,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAgB,CAAA;IACtC,CAAC,CAAA;IAED,OAAO,WAAW,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Error class for failures originating from the chifra daemon, or
3
+ * from the network transport between this client and the daemon.
4
+ *
5
+ * - `path` always holds the chifra endpoint that failed
6
+ * (e.g. `'/status'`, `'/blocks'`).
7
+ * - `status` is set when the daemon responded with a non-2xx HTTP
8
+ * status; absent when the failure was at the transport layer
9
+ * (DNS, connection refused, fetch threw).
10
+ * - `cause` is set when wrapping a transport-layer error so callers
11
+ * can drill into the original failure if needed.
12
+ */
13
+ export declare class TrueblocksError extends Error {
14
+ readonly path: string;
15
+ readonly status?: number;
16
+ constructor(message: string, init: {
17
+ path: string;
18
+ status?: number;
19
+ cause?: unknown;
20
+ });
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;gBAGtB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAW3D"}
package/dist/errors.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Error class for failures originating from the chifra daemon, or
3
+ * from the network transport between this client and the daemon.
4
+ *
5
+ * - `path` always holds the chifra endpoint that failed
6
+ * (e.g. `'/status'`, `'/blocks'`).
7
+ * - `status` is set when the daemon responded with a non-2xx HTTP
8
+ * status; absent when the failure was at the transport layer
9
+ * (DNS, connection refused, fetch threw).
10
+ * - `cause` is set when wrapping a transport-layer error so callers
11
+ * can drill into the original failure if needed.
12
+ */
13
+ export class TrueblocksError extends Error {
14
+ constructor(message, init) {
15
+ super(message);
16
+ this.name = 'TrueblocksError';
17
+ this.path = init.path;
18
+ this.status = init.status;
19
+ if (init.cause !== undefined) {
20
+ // ES2022 Error.cause; assigned post-super for ES2020 target compat.
21
+ ;
22
+ this.cause = init.cause;
23
+ }
24
+ }
25
+ }
26
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAIxC,YACE,OAAe,EACf,IAAwD;QAExD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,oEAAoE;YACpE,CAAC;YAAC,IAA4B,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACnD,CAAC;IACH,CAAC;CACF"}