@thru/thru-sdk 0.1.25 → 0.1.29
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 +166 -14
- package/dist/{VersionInfo-B13I6BVC.d.ts → VersionInfo-BLq6Evyp.d.ts} +722 -562
- package/dist/{chunk-M3N53HZF.js → chunk-QJACP7VX.js} +604 -242
- package/dist/chunk-QJACP7VX.js.map +1 -0
- package/dist/client.d.ts +16 -2
- package/dist/client.js +15 -17
- package/dist/client.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk.d.ts +4 -4
- package/dist/sdk.js +137 -2
- package/dist/sdk.js.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-M3N53HZF.js.map +0 -1
package/README.md
CHANGED
|
@@ -67,6 +67,29 @@ for await (const update of thru.streaming.trackTransaction(signature)) {
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Client Configuration
|
|
71
|
+
|
|
72
|
+
`createThruClient` accepts advanced transport options so you can customize networking, interceptors, and default call behaviour:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const thru = createThruClient({
|
|
76
|
+
baseUrl: "https://grpc-web.alphanet.thruput.org",
|
|
77
|
+
transportOptions: {
|
|
78
|
+
useBinaryFormat: false,
|
|
79
|
+
defaultTimeoutMs: 10_000,
|
|
80
|
+
},
|
|
81
|
+
interceptors: [authInterceptor],
|
|
82
|
+
callOptions: {
|
|
83
|
+
timeoutMs: 5_000,
|
|
84
|
+
headers: [["x-team", "sdk"]],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- `transportOptions` are passed to `createGrpcWebTransport`. Provide custom fetch implementations, JSON/binary options, or merge additional interceptors.
|
|
90
|
+
- `interceptors` let you append cross-cutting logic (auth, metrics) without re-implementing transports.
|
|
91
|
+
- `callOptions` act as defaults for **every** RPC. You can set timeouts, headers, or a shared `AbortSignal`, and each module call merges in per-request overrides.
|
|
92
|
+
|
|
70
93
|
## Domain Models
|
|
71
94
|
|
|
72
95
|
The SDK revolves around immutable domain classes. They copy mutable buffers, expose clear invariants, and provide conversion helpers where needed.
|
|
@@ -87,6 +110,117 @@ All classes are exported from the root package for easy access:
|
|
|
87
110
|
import { Block, Account, ChainEvent } from "@thru/thru-sdk";
|
|
88
111
|
```
|
|
89
112
|
|
|
113
|
+
## View Options
|
|
114
|
+
|
|
115
|
+
When fetching resources, you can control which parts of the resource are returned using view options. This allows you to optimize network usage by only fetching the data you need.
|
|
116
|
+
|
|
117
|
+
### AccountView
|
|
118
|
+
|
|
119
|
+
Controls which sections of account resources are returned:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { AccountView } from "@thru/thru-sdk";
|
|
123
|
+
|
|
124
|
+
// Fetch only the account address (lightweight existence check)
|
|
125
|
+
const account = await thru.accounts.get(address, {
|
|
126
|
+
view: AccountView.PUBKEY_ONLY,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Fetch only account metadata (balance, flags, owner, etc.)
|
|
130
|
+
const account = await thru.accounts.get(address, {
|
|
131
|
+
view: AccountView.META_ONLY,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Fetch only account data bytes (program data)
|
|
135
|
+
const account = await thru.accounts.get(address, {
|
|
136
|
+
view: AccountView.DATA_ONLY,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Fetch everything: address, metadata, and data (default)
|
|
140
|
+
const account = await thru.accounts.get(address, {
|
|
141
|
+
view: AccountView.FULL,
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
| View Option | Returns | Use Case |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| `AccountView.PUBKEY_ONLY` | Only the account `address` | Quick existence check |
|
|
148
|
+
| `AccountView.META_ONLY` | `address` + `meta` (balance, flags, owner, dataSize, seq, nonce) | Display account summary without data |
|
|
149
|
+
| `AccountView.DATA_ONLY` | `address` + `data` (raw bytes) | Fetch program data without metadata |
|
|
150
|
+
| `AccountView.FULL` | `address` + `meta` + `data` | Complete account information |
|
|
151
|
+
|
|
152
|
+
### BlockView
|
|
153
|
+
|
|
154
|
+
Controls how much of a block resource is returned:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { BlockView } from "@thru/thru-sdk";
|
|
158
|
+
|
|
159
|
+
// Fetch only block header (slot, hash, producer, etc.)
|
|
160
|
+
const block = await thru.blocks.get({ slot }, {
|
|
161
|
+
view: BlockView.HEADER_ONLY,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Fetch header and footer (execution status)
|
|
165
|
+
const block = await thru.blocks.get({ slot }, {
|
|
166
|
+
view: BlockView.HEADER_AND_FOOTER,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Fetch only block body (transactions)
|
|
170
|
+
const block = await thru.blocks.get({ slot }, {
|
|
171
|
+
view: BlockView.BODY_ONLY,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Fetch everything: header, body, and footer (default)
|
|
175
|
+
const block = await thru.blocks.get({ slot }, {
|
|
176
|
+
view: BlockView.FULL,
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
| View Option | Returns | Use Case |
|
|
181
|
+
| --- | --- | --- |
|
|
182
|
+
| `BlockView.HEADER_ONLY` | Only block `header` (metadata) | Display block summary without transactions |
|
|
183
|
+
| `BlockView.HEADER_AND_FOOTER` | `header` + `footer` (execution status) | Check execution status without transactions |
|
|
184
|
+
| `BlockView.BODY_ONLY` | Only block `body` (transactions) | Fetch transactions without header metadata |
|
|
185
|
+
| `BlockView.FULL` | `header` + `body` + `footer` | Complete block information |
|
|
186
|
+
|
|
187
|
+
### TransactionView
|
|
188
|
+
|
|
189
|
+
Controls how much of a transaction resource is returned:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { TransactionView } from "@thru/thru-sdk";
|
|
193
|
+
|
|
194
|
+
// Fetch only transaction signature
|
|
195
|
+
const tx = await thru.transactions.get(signature, {
|
|
196
|
+
view: TransactionView.SIGNATURE_ONLY,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Fetch only transaction header (signature, fee payer, etc.)
|
|
200
|
+
const tx = await thru.transactions.get(signature, {
|
|
201
|
+
view: TransactionView.HEADER_ONLY,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Fetch header and body (instructions)
|
|
205
|
+
const tx = await thru.transactions.get(signature, {
|
|
206
|
+
view: TransactionView.HEADER_AND_BODY,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Fetch everything: header, body, and execution results (default)
|
|
210
|
+
const tx = await thru.transactions.get(signature, {
|
|
211
|
+
view: TransactionView.FULL,
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
| View Option | Returns | Use Case |
|
|
216
|
+
| --- | --- | --- |
|
|
217
|
+
| `TransactionView.SIGNATURE_ONLY` | Only transaction `signature` | Quick existence check |
|
|
218
|
+
| `TransactionView.HEADER_ONLY` | Only transaction `header` (signature, fee payer, compute budget) | Display transaction summary without instructions |
|
|
219
|
+
| `TransactionView.HEADER_AND_BODY` | `header` + `body` (instructions) | Fetch transaction without execution results |
|
|
220
|
+
| `TransactionView.FULL` | `header` + `body` + execution results | Complete transaction information |
|
|
221
|
+
|
|
222
|
+
**Note:** If no view is specified, the default is `FULL` for all resource types.
|
|
223
|
+
|
|
90
224
|
## Streaming APIs
|
|
91
225
|
|
|
92
226
|
Every streaming endpoint yields an async iterable of domain models:
|
|
@@ -120,23 +254,17 @@ for await (const update of thru.streaming.trackTransaction(signature)) {
|
|
|
120
254
|
Server-side filtering is supported everywhere via CEL expressions:
|
|
121
255
|
|
|
122
256
|
```ts
|
|
123
|
-
import {
|
|
124
|
-
import {
|
|
125
|
-
FilterSchema,
|
|
126
|
-
FilterParamValueSchema,
|
|
127
|
-
} from "@thru/thru-sdk";
|
|
257
|
+
import { Filter, FilterParamValue } from "@thru/thru-sdk";
|
|
128
258
|
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
expression: "meta.owner.value == params.owner_bytes",
|
|
136
|
-
params: { owner_bytes: ownerParam },
|
|
259
|
+
const ownerFilter = new Filter({
|
|
260
|
+
expression: "account.meta.owner.value == params.owner",
|
|
261
|
+
params: {
|
|
262
|
+
owner: FilterParamValue.pubkey("taExampleAddress..."),
|
|
263
|
+
min_balance: FilterParamValue.uint(1_000_000n),
|
|
264
|
+
},
|
|
137
265
|
});
|
|
138
266
|
|
|
139
|
-
const accounts = await thru.accounts.list({ filter });
|
|
267
|
+
const accounts = await thru.accounts.list({ filter: ownerFilter });
|
|
140
268
|
```
|
|
141
269
|
|
|
142
270
|
Accepted parameter kinds:
|
|
@@ -145,11 +273,18 @@ Accepted parameter kinds:
|
|
|
145
273
|
- `boolValue`
|
|
146
274
|
- `intValue`
|
|
147
275
|
- `doubleValue`
|
|
276
|
+
- `uintValue`
|
|
277
|
+
- `pubkeyValue`
|
|
278
|
+
- `signatureValue`
|
|
279
|
+
- `taPubkeyValue`
|
|
280
|
+
- `tsSignatureValue`
|
|
148
281
|
|
|
149
282
|
Functions that take filters:
|
|
150
283
|
- List APIs: `thru.accounts.list`, `thru.blocks.list`, `thru.transactions.listForAccount`
|
|
151
284
|
- Streams: `thru.streaming.streamBlocks`, `thru.streaming.streamAccountUpdates`, `thru.streaming.streamTransactions`, `thru.streaming.streamEvents`
|
|
152
285
|
|
|
286
|
+
Use the helper constructors on `FilterParamValue` to safely build parameters from raw bytes, ta/ts-encoded strings, or simple numbers.
|
|
287
|
+
|
|
153
288
|
## Modules Overview
|
|
154
289
|
|
|
155
290
|
- `thru.blocks` — fetch/stream blocks and height snapshots
|
|
@@ -157,7 +292,24 @@ Functions that take filters:
|
|
|
157
292
|
- `thru.transactions` — build, sign, submit, track, and inspect transactions
|
|
158
293
|
- `thru.events` — query event history
|
|
159
294
|
- `thru.proofs` — generate state proofs
|
|
295
|
+
- `thru.consensus` — build version contexts and stringify consensus states
|
|
160
296
|
- `thru.streaming` — streaming wrappers for blocks, accounts, transactions, events
|
|
161
297
|
- `thru.helpers` — address, signature, and block-hash conversion helpers
|
|
162
298
|
|
|
163
299
|
The public surface is fully domain-based; reaching for lower-level protobuf structures is no longer necessary.
|
|
300
|
+
|
|
301
|
+
## Streaming helpers
|
|
302
|
+
|
|
303
|
+
Async iterable utilities make it easier to consume streaming APIs:
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
import { collectStream, firstStreamValue } from "@thru/thru-sdk";
|
|
307
|
+
|
|
308
|
+
const updates = await collectStream(thru.streaming.streamBlocks({ startSlot: height.finalized }), {
|
|
309
|
+
limit: 5,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const firstEvent = await firstStreamValue(thru.streaming.streamEvents());
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
`collectStream` gathers values (optionally respecting `AbortSignal`s), `firstStreamValue` returns the first item, and `forEachStreamValue` lets you run async handlers for each streamed update.
|