@thru/thru-sdk 0.1.22 → 0.1.24
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 +96 -74
- package/dist/{transactions-CLezIeXO.d.ts → VersionInfo-B13I6BVC.d.ts} +649 -447
- package/dist/{chunk-SHMREHP5.js → chunk-M3N53HZF.js} +1363 -214
- package/dist/chunk-M3N53HZF.js.map +1 -0
- package/dist/client.d.ts +3 -3
- package/dist/client.js +3 -3
- 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 +236 -1
- package/dist/sdk.js.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-SHMREHP5.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @thru/thru-sdk
|
|
2
2
|
|
|
3
|
-
Typed TypeScript/JavaScript client for talking to the Thru blockchain.
|
|
3
|
+
Typed TypeScript/JavaScript client for talking to the Thru blockchain. The SDK exposes rich domain models (blocks, accounts, transactions, events, proofs) that hide the underlying protobuf transport.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ npm install @thru/thru-sdk
|
|
|
10
10
|
|
|
11
11
|
### TypeScript Configuration
|
|
12
12
|
|
|
13
|
-
For optimal import resolution,
|
|
13
|
+
For optimal import resolution, use modern module resolution:
|
|
14
14
|
|
|
15
15
|
```json
|
|
16
16
|
{
|
|
@@ -23,119 +23,141 @@ For optimal import resolution, we recommend using modern TypeScript module resol
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
If you're using a bundler (Vite, Webpack, esbuild, etc.) or modern build tools, `moduleResolution: "bundler"` is the recommended setting. For Node.js projects, you can also use `"node16"` or `"nodenext"`.
|
|
26
|
+
If you rely on Node’s ESM support without a bundler, use `"moduleResolution": "nodenext"`.
|
|
29
27
|
|
|
30
28
|
## Basic Usage
|
|
31
29
|
|
|
32
30
|
```ts
|
|
33
|
-
import { createThruClient } from
|
|
31
|
+
import { createThruClient } from "@thru/thru-sdk";
|
|
32
|
+
import {
|
|
33
|
+
Account,
|
|
34
|
+
Block,
|
|
35
|
+
ChainEvent,
|
|
36
|
+
Transaction,
|
|
37
|
+
TransactionStatusSnapshot,
|
|
38
|
+
} from "@thru/thru-sdk";
|
|
34
39
|
|
|
35
|
-
// Point at the default public alpha cluster or override with your own URL
|
|
36
40
|
const thru = createThruClient({
|
|
37
|
-
baseUrl:
|
|
41
|
+
baseUrl: "https://grpc-web.alphanet.thruput.org",
|
|
38
42
|
});
|
|
39
43
|
|
|
40
|
-
// Fetch the
|
|
41
|
-
const
|
|
42
|
-
const latestBlock = await thru.blocks.get({ slot: finalized });
|
|
44
|
+
// Fetch the latest finalized block
|
|
45
|
+
const height = await thru.blocks.getBlockHeight();
|
|
46
|
+
const latestBlock: Block = await thru.blocks.get({ slot: height.finalized });
|
|
47
|
+
console.log(latestBlock.header.blockHash);
|
|
43
48
|
|
|
44
|
-
//
|
|
45
|
-
const account = await thru.accounts.get(
|
|
49
|
+
// Fetch an account – returns the Account domain object
|
|
50
|
+
const account: Account = await thru.accounts.get("taExampleAddress...");
|
|
51
|
+
console.log(account.meta?.balance);
|
|
46
52
|
|
|
47
|
-
// Build, sign, and
|
|
53
|
+
// Build, sign, submit, and track a transaction
|
|
48
54
|
const { rawTransaction, signature } = await thru.transactions.buildAndSign({
|
|
49
55
|
feePayer: {
|
|
50
|
-
publicKey:
|
|
56
|
+
publicKey: "taFeePayerAddress...",
|
|
51
57
|
privateKey: feePayerSecretKeyBytes,
|
|
52
58
|
},
|
|
53
59
|
program: programIdentifierBytes,
|
|
54
60
|
});
|
|
55
61
|
await thru.transactions.send(rawTransaction);
|
|
62
|
+
|
|
63
|
+
// Track the transaction – emits domain snapshots
|
|
64
|
+
for await (const update of thru.streaming.trackTransaction(signature)) {
|
|
65
|
+
console.log(update.status, update.executionResult?.consumedComputeUnits);
|
|
66
|
+
if (update.statusCode === ConsensusStatus.FINALIZED) break;
|
|
67
|
+
}
|
|
56
68
|
```
|
|
57
69
|
|
|
58
|
-
|
|
70
|
+
## Domain Models
|
|
59
71
|
|
|
60
|
-
|
|
72
|
+
The SDK revolves around immutable domain classes. They copy mutable buffers, expose clear invariants, and provide conversion helpers where needed.
|
|
61
73
|
|
|
62
|
-
|
|
74
|
+
| API surface | Domain class |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| Blocks | `Block`, `BlockHeader`, `BlockFooter` |
|
|
77
|
+
| Accounts | `Account`, `AccountMeta`, `AccountData` |
|
|
78
|
+
| Transactions | `Transaction`, `TransactionStatusSnapshot`, `TrackTransactionUpdate` |
|
|
79
|
+
| Events | `ChainEvent` |
|
|
80
|
+
| Proofs | `StateProof` |
|
|
81
|
+
| Height | `HeightSnapshot` |
|
|
82
|
+
| Node version | `VersionInfo` |
|
|
83
|
+
|
|
84
|
+
All classes are exported from the root package for easy access:
|
|
63
85
|
|
|
64
86
|
```ts
|
|
65
|
-
import {
|
|
66
|
-
|
|
67
|
-
FilterSchema,
|
|
68
|
-
FilterParamValueSchema,
|
|
69
|
-
type Filter,
|
|
70
|
-
type FilterParamValue
|
|
71
|
-
} from "@thru/thru-sdk";
|
|
87
|
+
import { Block, Account, ChainEvent } from "@thru/thru-sdk";
|
|
88
|
+
```
|
|
72
89
|
|
|
73
|
-
|
|
74
|
-
const paramValue = create(FilterParamValueSchema, {
|
|
75
|
-
kind: {
|
|
76
|
-
case: "bytesValue", // or "stringValue", "boolValue", "intValue", "doubleValue"
|
|
77
|
-
value: new Uint8Array(32), // the actual value
|
|
78
|
-
},
|
|
79
|
-
});
|
|
90
|
+
## Streaming APIs
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
const filter = create(FilterSchema, {
|
|
83
|
-
expression: "meta.owner.value == params.owner_bytes",
|
|
84
|
-
params: {
|
|
85
|
-
owner_bytes: paramValue,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
```
|
|
92
|
+
Every streaming endpoint yields an async iterable of domain models:
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
```ts
|
|
95
|
+
// Blocks
|
|
96
|
+
for await (const { block } of thru.streaming.streamBlocks()) {
|
|
97
|
+
console.log(block.header.slot);
|
|
98
|
+
}
|
|
91
99
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
// Account updates
|
|
101
|
+
for await (const { update } of thru.streaming.streamAccountUpdates("taAddress")) {
|
|
102
|
+
if (update.kind === "snapshot") {
|
|
103
|
+
console.log(update.snapshot.account.meta?.balance);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
98
106
|
|
|
99
|
-
|
|
107
|
+
// Events
|
|
108
|
+
for await (const { event } of thru.streaming.streamEvents()) {
|
|
109
|
+
console.log((event as ChainEvent).timestampNs);
|
|
110
|
+
}
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
// Transaction tracking
|
|
113
|
+
for await (const update of thru.streaming.trackTransaction(signature)) {
|
|
114
|
+
console.log(update.status, update.executionResult?.consumedComputeUnits);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
105
117
|
|
|
106
|
-
|
|
107
|
-
- `thru.streaming.streamBlocks({ filter })` - Stream blocks with filtering
|
|
108
|
-
- `thru.streaming.streamAccountUpdates(address, { filter })` - Stream account updates with filtering
|
|
109
|
-
- `thru.streaming.streamTransactions({ filter })` - Stream transactions with filtering
|
|
110
|
-
- `thru.streaming.streamEvents({ filter })` - Stream events with filtering
|
|
118
|
+
## Filters
|
|
111
119
|
|
|
112
|
-
|
|
120
|
+
Server-side filtering is supported everywhere via CEL expressions:
|
|
113
121
|
|
|
114
122
|
```ts
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
import { create } from "@bufbuild/protobuf";
|
|
124
|
+
import {
|
|
125
|
+
FilterSchema,
|
|
126
|
+
FilterParamValueSchema,
|
|
127
|
+
} from "@thru/thru-sdk";
|
|
117
128
|
|
|
129
|
+
const ownerBytes = new Uint8Array(32);
|
|
118
130
|
const ownerParam = create(FilterParamValueSchema, {
|
|
119
|
-
kind: {
|
|
120
|
-
case: "bytesValue",
|
|
121
|
-
value: ownerBytes,
|
|
122
|
-
},
|
|
131
|
+
kind: { case: "bytesValue", value: ownerBytes },
|
|
123
132
|
});
|
|
124
133
|
|
|
125
134
|
const filter = create(FilterSchema, {
|
|
126
135
|
expression: "meta.owner.value == params.owner_bytes",
|
|
127
|
-
params: {
|
|
128
|
-
owner_bytes: ownerParam,
|
|
129
|
-
},
|
|
136
|
+
params: { owner_bytes: ownerParam },
|
|
130
137
|
});
|
|
131
138
|
|
|
132
|
-
const
|
|
139
|
+
const accounts = await thru.accounts.list({ filter });
|
|
133
140
|
```
|
|
134
141
|
|
|
135
|
-
|
|
142
|
+
Accepted parameter kinds:
|
|
143
|
+
- `stringValue`
|
|
144
|
+
- `bytesValue`
|
|
145
|
+
- `boolValue`
|
|
146
|
+
- `intValue`
|
|
147
|
+
- `doubleValue`
|
|
148
|
+
|
|
149
|
+
Functions that take filters:
|
|
150
|
+
- List APIs: `thru.accounts.list`, `thru.blocks.list`, `thru.transactions.listForAccount`
|
|
151
|
+
- Streams: `thru.streaming.streamBlocks`, `thru.streaming.streamAccountUpdates`, `thru.streaming.streamTransactions`, `thru.streaming.streamEvents`
|
|
152
|
+
|
|
153
|
+
## Modules Overview
|
|
154
|
+
|
|
155
|
+
- `thru.blocks` — fetch/stream blocks and height snapshots
|
|
156
|
+
- `thru.accounts` — read account state or build create-account transactions
|
|
157
|
+
- `thru.transactions` — build, sign, submit, track, and inspect transactions
|
|
158
|
+
- `thru.events` — query event history
|
|
159
|
+
- `thru.proofs` — generate state proofs
|
|
160
|
+
- `thru.streaming` — streaming wrappers for blocks, accounts, transactions, events
|
|
161
|
+
- `thru.helpers` — address, signature, and block-hash conversion helpers
|
|
136
162
|
|
|
137
|
-
|
|
138
|
-
- `thru.accounts` — fetch account state, list owned accounts, and generate create-account transactions
|
|
139
|
-
- `thru.transactions` — build transactions locally, sign them, submit, and inspect status
|
|
140
|
-
- `thru.events` / `thru.proofs` — retrieve on-chain events and generate state proofs
|
|
141
|
-
- `thru.helpers` — convert to/from Thru identifiers (addresses, signatures, block hashes) and derive program addresses
|
|
163
|
+
The public surface is fully domain-based; reaching for lower-level protobuf structures is no longer necessary.
|