@thru/thru-sdk 0.1.25 → 0.1.28

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
@@ -87,6 +87,117 @@ All classes are exported from the root package for easy access:
87
87
  import { Block, Account, ChainEvent } from "@thru/thru-sdk";
88
88
  ```
89
89
 
90
+ ## View Options
91
+
92
+ 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.
93
+
94
+ ### AccountView
95
+
96
+ Controls which sections of account resources are returned:
97
+
98
+ ```ts
99
+ import { AccountView } from "@thru/thru-sdk";
100
+
101
+ // Fetch only the account address (lightweight existence check)
102
+ const account = await thru.accounts.get(address, {
103
+ view: AccountView.PUBKEY_ONLY,
104
+ });
105
+
106
+ // Fetch only account metadata (balance, flags, owner, etc.)
107
+ const account = await thru.accounts.get(address, {
108
+ view: AccountView.META_ONLY,
109
+ });
110
+
111
+ // Fetch only account data bytes (program data)
112
+ const account = await thru.accounts.get(address, {
113
+ view: AccountView.DATA_ONLY,
114
+ });
115
+
116
+ // Fetch everything: address, metadata, and data (default)
117
+ const account = await thru.accounts.get(address, {
118
+ view: AccountView.FULL,
119
+ });
120
+ ```
121
+
122
+ | View Option | Returns | Use Case |
123
+ | --- | --- | --- |
124
+ | `AccountView.PUBKEY_ONLY` | Only the account `address` | Quick existence check |
125
+ | `AccountView.META_ONLY` | `address` + `meta` (balance, flags, owner, dataSize, seq, nonce) | Display account summary without data |
126
+ | `AccountView.DATA_ONLY` | `address` + `data` (raw bytes) | Fetch program data without metadata |
127
+ | `AccountView.FULL` | `address` + `meta` + `data` | Complete account information |
128
+
129
+ ### BlockView
130
+
131
+ Controls how much of a block resource is returned:
132
+
133
+ ```ts
134
+ import { BlockView } from "@thru/thru-sdk";
135
+
136
+ // Fetch only block header (slot, hash, producer, etc.)
137
+ const block = await thru.blocks.get({ slot }, {
138
+ view: BlockView.HEADER_ONLY,
139
+ });
140
+
141
+ // Fetch header and footer (execution status)
142
+ const block = await thru.blocks.get({ slot }, {
143
+ view: BlockView.HEADER_AND_FOOTER,
144
+ });
145
+
146
+ // Fetch only block body (transactions)
147
+ const block = await thru.blocks.get({ slot }, {
148
+ view: BlockView.BODY_ONLY,
149
+ });
150
+
151
+ // Fetch everything: header, body, and footer (default)
152
+ const block = await thru.blocks.get({ slot }, {
153
+ view: BlockView.FULL,
154
+ });
155
+ ```
156
+
157
+ | View Option | Returns | Use Case |
158
+ | --- | --- | --- |
159
+ | `BlockView.HEADER_ONLY` | Only block `header` (metadata) | Display block summary without transactions |
160
+ | `BlockView.HEADER_AND_FOOTER` | `header` + `footer` (execution status) | Check execution status without transactions |
161
+ | `BlockView.BODY_ONLY` | Only block `body` (transactions) | Fetch transactions without header metadata |
162
+ | `BlockView.FULL` | `header` + `body` + `footer` | Complete block information |
163
+
164
+ ### TransactionView
165
+
166
+ Controls how much of a transaction resource is returned:
167
+
168
+ ```ts
169
+ import { TransactionView } from "@thru/thru-sdk";
170
+
171
+ // Fetch only transaction signature
172
+ const tx = await thru.transactions.get(signature, {
173
+ view: TransactionView.SIGNATURE_ONLY,
174
+ });
175
+
176
+ // Fetch only transaction header (signature, fee payer, etc.)
177
+ const tx = await thru.transactions.get(signature, {
178
+ view: TransactionView.HEADER_ONLY,
179
+ });
180
+
181
+ // Fetch header and body (instructions)
182
+ const tx = await thru.transactions.get(signature, {
183
+ view: TransactionView.HEADER_AND_BODY,
184
+ });
185
+
186
+ // Fetch everything: header, body, and execution results (default)
187
+ const tx = await thru.transactions.get(signature, {
188
+ view: TransactionView.FULL,
189
+ });
190
+ ```
191
+
192
+ | View Option | Returns | Use Case |
193
+ | --- | --- | --- |
194
+ | `TransactionView.SIGNATURE_ONLY` | Only transaction `signature` | Quick existence check |
195
+ | `TransactionView.HEADER_ONLY` | Only transaction `header` (signature, fee payer, compute budget) | Display transaction summary without instructions |
196
+ | `TransactionView.HEADER_AND_BODY` | `header` + `body` (instructions) | Fetch transaction without execution results |
197
+ | `TransactionView.FULL` | `header` + `body` + execution results | Complete transaction information |
198
+
199
+ **Note:** If no view is specified, the default is `FULL` for all resource types.
200
+
90
201
  ## Streaming APIs
91
202
 
92
203
  Every streaming endpoint yields an async iterable of domain models: