@mysten/walrus 1.0.4 → 1.1.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.
- package/CHANGELOG.md +28 -0
- package/README.md +52 -0
- package/dist/client.d.mts +108 -36
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +177 -345
- package/dist/client.mjs.map +1 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +2 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/contracts/utils/index.d.mts.map +1 -1
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/contracts/walrus/blob.d.mts +12 -12
- package/dist/contracts/walrus/blob.d.mts.map +1 -1
- package/dist/contracts/walrus/storage_node.d.mts +8 -8
- package/dist/contracts/walrus/storage_node.d.mts.map +1 -1
- package/dist/error.d.mts.map +1 -1
- package/dist/files/blob.d.mts.map +1 -1
- package/dist/files/file.d.mts.map +1 -1
- package/dist/files/readers/blob.d.mts.map +1 -1
- package/dist/files/readers/quilt-file.d.mts +0 -1
- package/dist/files/readers/quilt-file.d.mts.map +1 -1
- package/dist/files/readers/quilt.d.mts.map +1 -1
- package/dist/flows/write-blob.mjs +227 -0
- package/dist/flows/write-blob.mjs.map +1 -0
- package/dist/flows/write-files.mjs +112 -0
- package/dist/flows/write-files.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/storage-node/client.d.mts.map +1 -1
- package/dist/storage-node/client.mjs +14 -0
- package/dist/storage-node/client.mjs.map +1 -1
- package/dist/storage-node/error.d.mts.map +1 -1
- package/dist/storage-node/types.d.mts +2 -1
- package/dist/storage-node/types.d.mts.map +1 -1
- package/dist/storage-node/utils.d.mts.map +1 -1
- package/dist/types.d.mts +82 -30
- package/dist/types.d.mts.map +1 -1
- package/dist/upload-relay/client.d.mts.map +1 -1
- package/dist/utils/bcs.d.mts +1 -2
- package/dist/utils/bcs.d.mts.map +1 -1
- package/dist/utils/bcs.mjs +14 -1
- package/dist/utils/bcs.mjs.map +1 -1
- package/dist/utils/quilts.d.mts +0 -1
- package/dist/utils/quilts.d.mts.map +1 -1
- package/docs/index.md +174 -129
- package/package.json +9 -9
package/docs/index.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
> Store and retrieve blobs on Walrus decentralized storage
|
|
4
4
|
|
|
5
|
+
The Walrus TypeScript SDK works directly with Walrus storage nodes or with the Walrus upload relay.
|
|
6
|
+
When you use the Walrus SDK without an upload relay, reading and writing Walrus blobs requires many
|
|
7
|
+
requests (approximately 2200 to write a blob and approximately 335 to read a blob). The upload relay
|
|
8
|
+
reduces the number of requests needed to write a blob, but reads through the Walrus SDK still
|
|
9
|
+
require many requests. For many applications, using publishers and aggregators is recommended, but
|
|
10
|
+
the TypeScript SDK is useful when building applications where the application needs to directly
|
|
11
|
+
interact with Walrus, or when users need to pay for their own storage directly.
|
|
12
|
+
|
|
13
|
+
The Walrus SDK exposes high-level methods for reading and writing blobs, as well as lower-level
|
|
14
|
+
methods for the individual steps in the process. You can use the lower-level methods to implement
|
|
15
|
+
more complex flows when you want more control over optimization.
|
|
16
|
+
|
|
5
17
|
## Installation
|
|
6
18
|
|
|
7
19
|
```bash npm2yarn
|
|
@@ -10,8 +22,8 @@ npm install --save @mysten/walrus @mysten/sui
|
|
|
10
22
|
|
|
11
23
|
## Setup
|
|
12
24
|
|
|
13
|
-
To use the
|
|
14
|
-
|
|
25
|
+
To use the Walrus SDK, you need to create a client from the TypeScript SDK and extend it with the
|
|
26
|
+
Walrus SDK.
|
|
15
27
|
|
|
16
28
|
```ts
|
|
17
29
|
const client = new SuiGrpcClient({
|
|
@@ -20,9 +32,9 @@ const client = new SuiGrpcClient({
|
|
|
20
32
|
}).$extend(walrus());
|
|
21
33
|
```
|
|
22
34
|
|
|
23
|
-
The
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
The Walrus SDK includes all the relevant package and object IDs needed for connecting to Testnet.
|
|
36
|
+
You can also manually configure the Walrus SDK to use a different set of IDs, allowing you to
|
|
37
|
+
connect to a different network or updated deployment of the Walrus contracts.
|
|
26
38
|
|
|
27
39
|
```ts
|
|
28
40
|
const client = new SuiGrpcClient({
|
|
@@ -38,7 +50,7 @@ const client = new SuiGrpcClient({
|
|
|
38
50
|
);
|
|
39
51
|
```
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
Some environments require you to customize how data is fetched:
|
|
42
54
|
|
|
43
55
|
```ts
|
|
44
56
|
const client = new SuiGrpcClient({
|
|
@@ -57,37 +69,22 @@ const client = new SuiGrpcClient({
|
|
|
57
69
|
);
|
|
58
70
|
```
|
|
59
71
|
|
|
60
|
-
|
|
61
|
-
any other desired behavior.
|
|
62
|
-
|
|
63
|
-
## SDK Overview
|
|
64
|
-
|
|
65
|
-
The Walrus TS SDK is designed to work directly with walrus storage nodes, or with the walrus upload
|
|
66
|
-
relay. When using the walrus SDK without an upload relay, it is important to understand that reading
|
|
67
|
-
and writing walrus blobs requires a lot of requests (~2200 to write a blob, ~335 to read a blob).
|
|
68
|
-
The upload relay will reduce the number of requests needed to write a blob, but reads through the
|
|
69
|
-
walrus SDK will still require a lot of requests. For many applications, using publishers and
|
|
70
|
-
aggregators is recommended, but the TS SDK can be useful when building applications where the
|
|
71
|
-
application needs to directly interact with walrus or users need to pay for their own storage
|
|
72
|
-
directly.
|
|
73
|
-
|
|
74
|
-
The walrus sdk exposes high level methods for reading and writing blobs, as well as lower level
|
|
75
|
-
methods for the individual steps in the process that can be used to implement more complex flows
|
|
76
|
-
when you want more control to implement more optimized implementations.
|
|
72
|
+
You can use this approach to implement a fetch function with custom timeouts, rate limits, retry
|
|
73
|
+
logic, or any other desired behavior.
|
|
77
74
|
|
|
78
|
-
##
|
|
75
|
+
## `WalrusFile` API
|
|
79
76
|
|
|
80
|
-
The `WalrusFile` API provides a higher
|
|
81
|
-
about how data is stored in
|
|
82
|
-
|
|
77
|
+
The `WalrusFile` API provides a higher-level abstraction so that applications do not need to worry
|
|
78
|
+
about how data is stored in Walrus. It handles data stored directly in blobs and data stored in
|
|
79
|
+
quilts, but might expand to cover other storage patterns in the future.
|
|
83
80
|
|
|
84
81
|
### Reading files
|
|
85
82
|
|
|
86
|
-
To read files,
|
|
87
|
-
|
|
83
|
+
To read files, use the `getFiles` method. This method accepts both blob IDs and quilt IDs, and
|
|
84
|
+
returns a `WalrusFile`.
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
Read files in batches when possible, which allows the client to be more efficient when loading
|
|
87
|
+
multiple files from the same quilt.
|
|
91
88
|
|
|
92
89
|
```ts
|
|
93
90
|
const [file1, file2] = await client.walrus.getFiles({ ids: [anyBlobId, orQuiltId] });
|
|
@@ -104,17 +101,16 @@ const text = await file1.text();
|
|
|
104
101
|
const json = await file2.json();
|
|
105
102
|
```
|
|
106
103
|
|
|
107
|
-
A `WalrusFile`
|
|
108
|
-
quilt.
|
|
104
|
+
A `WalrusFile` might also have `identifier` and `tags` properties if the file was stored in a quilt.
|
|
109
105
|
|
|
110
106
|
```ts
|
|
111
107
|
const identifier: string | null = await file1.getIdentifier();
|
|
112
108
|
const tags: Record<string, string> = await file1.getTags();
|
|
113
109
|
```
|
|
114
110
|
|
|
115
|
-
|
|
111
|
+
#### `WalrusBlob`
|
|
116
112
|
|
|
117
|
-
You can also get a `WalrusBlob` instead of a `WalrusFile` if you have the blobId
|
|
113
|
+
You can also get a `WalrusBlob` instead of a `WalrusFile` if you have the `blobId`:
|
|
118
114
|
|
|
119
115
|
```ts
|
|
120
116
|
const blob = await client.walrus.getBlob({ blobId });
|
|
@@ -135,8 +131,8 @@ const filesById = await blob.files({ ids: [quiltID] });
|
|
|
135
131
|
|
|
136
132
|
### Writing files
|
|
137
133
|
|
|
138
|
-
You can also construct a `WalrusFile` from a `Uint8Array`, `Blob`, or a `string
|
|
139
|
-
|
|
134
|
+
You can also construct a `WalrusFile` from a `Uint8Array`, `Blob`, or a `string`, which you can then
|
|
135
|
+
store on Walrus:
|
|
140
136
|
|
|
141
137
|
```ts
|
|
142
138
|
const file1 = WalrusFile.from({
|
|
@@ -156,15 +152,15 @@ const file3 = WalrusFile.from({
|
|
|
156
152
|
});
|
|
157
153
|
```
|
|
158
154
|
|
|
159
|
-
|
|
155
|
+
After you have your files, use the `writeFiles` method to write them to Walrus.
|
|
160
156
|
|
|
161
|
-
Along with the files, you
|
|
162
|
-
transaction
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
157
|
+
Along with the files, you also need to provide a `Signer` instance that signs and pays for the
|
|
158
|
+
transaction and storage fees. The signer's address needs sufficient SUI to cover the transactions
|
|
159
|
+
that register the blob and certify its availability after upload. The signer must own sufficient WAL
|
|
160
|
+
to pay to store the blob for the specified number of epochs, as well as the write fee for writing
|
|
161
|
+
the blob.
|
|
166
162
|
|
|
167
|
-
The exact costs
|
|
163
|
+
The exact costs depend on the size of the blobs, as well as the current gas and storage prices.
|
|
168
164
|
|
|
169
165
|
```ts
|
|
170
166
|
const results: {
|
|
@@ -179,32 +175,32 @@ const results: {
|
|
|
179
175
|
});
|
|
180
176
|
```
|
|
181
177
|
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
The provided files are all written into a single quilt. Future versions of the SDK might optimize
|
|
179
|
+
how files are stored to be more efficient by splitting files into multiple quilts.
|
|
184
180
|
|
|
185
181
|
The current quilt encoding is less efficient for single files, so writing multiple files together is
|
|
186
182
|
recommended when possible. Writing raw blobs directly is also possible using the `writeBlob` API
|
|
187
|
-
|
|
183
|
+
described below.
|
|
188
184
|
|
|
189
|
-
|
|
185
|
+
#### Writing files in browser environments
|
|
190
186
|
|
|
191
|
-
When the transactions to upload a blob are signed by a wallet in a browser, some wallets
|
|
192
|
-
|
|
193
|
-
interaction,
|
|
187
|
+
When the transactions to upload a blob are signed by a wallet in a browser, some wallets use popups
|
|
188
|
+
to prompt you for a signature. If the popups are not opened in direct response to a user
|
|
189
|
+
interaction, the browser might block them.
|
|
194
190
|
|
|
195
|
-
To avoid this,
|
|
196
|
-
|
|
191
|
+
To avoid this, execute the transactions that register and certify the blob in separate event
|
|
192
|
+
handlers by creating separate buttons for each step.
|
|
197
193
|
|
|
198
194
|
The `client.writeFilesFlow` method returns an object with a set of methods that break the write flow
|
|
199
195
|
into several smaller steps:
|
|
200
196
|
|
|
201
|
-
1. `encode
|
|
202
|
-
2. `register
|
|
203
|
-
3. `upload
|
|
204
|
-
4. `certify
|
|
205
|
-
5. `listFiles
|
|
197
|
+
1. `encode`: Encodes the files and generates a `blobId`.
|
|
198
|
+
2. `register`: Returns a transaction that registers the blob onchain.
|
|
199
|
+
3. `upload`: Uploads the data to storage nodes.
|
|
200
|
+
4. `certify`: Returns a transaction that certifies the blob onchain.
|
|
201
|
+
5. `listFiles`: Returns a list of the created files.
|
|
206
202
|
|
|
207
|
-
|
|
203
|
+
The following simplified example shows the core API usage with separate user interactions:
|
|
208
204
|
|
|
209
205
|
```tsx
|
|
210
206
|
// Step 1: Create and encode the flow (can be done immediately when file is selected)
|
|
@@ -258,13 +254,51 @@ async function handleCertify() {
|
|
|
258
254
|
This approach ensures that each transaction signing step is separated into different user
|
|
259
255
|
interactions, allowing wallet popups to work properly without being blocked by the browser.
|
|
260
256
|
|
|
261
|
-
|
|
257
|
+
### Running the full flow
|
|
258
|
+
|
|
259
|
+
If you do not need separate user interactions for each step, use `run()` to execute the full
|
|
260
|
+
pipeline as an async iterator.
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
const flow = client.walrus.writeBlobFlow({ blob });
|
|
264
|
+
|
|
265
|
+
for await (const step of flow.run({ signer, epochs: 3, deletable: true })) {
|
|
266
|
+
await db.save(fileId, step); // persist for crash recovery
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The flow also provides `executeRegister` and `executeCertify` methods that handle signing and return
|
|
271
|
+
typed step results:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
const flow = client.walrus.writeBlobFlow({ blob });
|
|
275
|
+
const enc = await flow.encode();
|
|
276
|
+
const reg = await flow.executeRegister({ signer, epochs: 3, deletable: true, owner: address });
|
|
277
|
+
const up = await flow.upload({ digest: reg.txDigest });
|
|
278
|
+
const cert = await flow.executeCertify({ signer });
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### Resuming uploads
|
|
282
|
+
|
|
283
|
+
Each step executed by `run()` produces a `WriteBlobStep` that you can persist for crash recovery. To
|
|
284
|
+
resume an upload after a crash, pass a saved `WriteBlobStep` as `resume`. The flow skips completed
|
|
285
|
+
steps, validates the `blobId`, and only uploads slivers that are not already stored:
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
const saved = await db.load(fileId);
|
|
289
|
+
const flow = client.walrus.writeBlobFlow({ blob, resume: saved });
|
|
290
|
+
|
|
291
|
+
for await (const step of flow.run({ signer, epochs: 3, deletable: true })) {
|
|
292
|
+
await db.save(fileId, step);
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Using an upload relay
|
|
262
297
|
|
|
263
|
-
Writing blobs directly from a client requires
|
|
264
|
-
|
|
265
|
-
complexity for the client.
|
|
298
|
+
Writing blobs directly from a client requires many requests to write data to all the storage nodes.
|
|
299
|
+
An upload relay offloads the work of these writes to a server, reducing complexity for the client.
|
|
266
300
|
|
|
267
|
-
To use an upload relay,
|
|
301
|
+
To use an upload relay, add the `uploadRelay` option when adding the Walrus extension:
|
|
268
302
|
|
|
269
303
|
```ts
|
|
270
304
|
const client = new SuiGrpcClient({
|
|
@@ -282,18 +316,18 @@ const client = new SuiGrpcClient({
|
|
|
282
316
|
);
|
|
283
317
|
```
|
|
284
318
|
|
|
285
|
-
The `host` option is required
|
|
286
|
-
require a tip to
|
|
287
|
-
|
|
288
|
-
|
|
319
|
+
The `host` option is required and indicates the URL for your upload relay. Upload relays might
|
|
320
|
+
require a tip to cover the cost of writing the blob. You can configure a maximum tip (paid in MIST)
|
|
321
|
+
and the `WalrusClient` automatically determines the required tip for your upload relay. You can also
|
|
322
|
+
manually configure the tip as shown below.
|
|
289
323
|
|
|
290
|
-
|
|
291
|
-
`https://upload-relay.testnet.walrus.space/v1/tip-config`)
|
|
292
|
-
|
|
324
|
+
Find the tip required by an upload relay using the `tip-config` endpoint (for example,
|
|
325
|
+
`https://upload-relay.testnet.walrus.space/v1/tip-config`). The tip is either a `const` or a
|
|
326
|
+
`linear` type.
|
|
293
327
|
|
|
294
328
|
### `const` tip
|
|
295
329
|
|
|
296
|
-
A `const`
|
|
330
|
+
A `const` tip sends a fixed amount for each blob written to the upload relay.
|
|
297
331
|
|
|
298
332
|
```ts
|
|
299
333
|
const client = new SuiGrpcClient({
|
|
@@ -316,8 +350,8 @@ const client = new SuiGrpcClient({
|
|
|
316
350
|
|
|
317
351
|
### `linear` tip
|
|
318
352
|
|
|
319
|
-
A `linear` tip
|
|
320
|
-
|
|
353
|
+
A `linear` tip sends a fixed amount for each blob written to the upload relay, plus a multiplier
|
|
354
|
+
based on the size of the blob.
|
|
321
355
|
|
|
322
356
|
```ts
|
|
323
357
|
const client = new SuiGrpcClient({
|
|
@@ -343,22 +377,22 @@ const client = new SuiGrpcClient({
|
|
|
343
377
|
|
|
344
378
|
## Interacting with blobs directly
|
|
345
379
|
|
|
346
|
-
|
|
347
|
-
|
|
380
|
+
If you do not want to use the `WalrusFile` abstractions, use the `readBlob` and `writeBlob` APIs
|
|
381
|
+
directly.
|
|
348
382
|
|
|
349
383
|
### Reading blobs
|
|
350
384
|
|
|
351
|
-
The `readBlob` method
|
|
385
|
+
The `readBlob` method reads a blob given the `blobId` and returns a `Uint8Array` containing the blob
|
|
352
386
|
content:
|
|
353
387
|
|
|
354
388
|
```ts
|
|
355
389
|
const blob = await client.walrus.readBlob({ blobId });
|
|
356
390
|
```
|
|
357
391
|
|
|
358
|
-
### Writing
|
|
392
|
+
### Writing blobs
|
|
359
393
|
|
|
360
|
-
The writeBlob method
|
|
361
|
-
|
|
394
|
+
The `writeBlob` method writes a blob (as a `Uint8Array`) to Walrus. You need to specify how long the
|
|
395
|
+
blob should be stored for and whether the blob should be deletable.
|
|
362
396
|
|
|
363
397
|
```ts
|
|
364
398
|
const file = new TextEncoder().encode('Hello from the TS SDK!!!\n');
|
|
@@ -371,26 +405,27 @@ const { blobId } = await client.walrus.writeBlob({
|
|
|
371
405
|
});
|
|
372
406
|
```
|
|
373
407
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
For a complete overview of the available methods on the `WalrusClient` you can reference type
|
|
377
|
-
[TypeDocs](/typedoc/classes/_mysten_walrus.WalrusClient.html)
|
|
378
|
-
|
|
379
|
-
## Examples
|
|
408
|
+
`writeBlob` and `writeFiles` also support `onStep` and `resume` for crash-recoverable uploads:
|
|
380
409
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
410
|
+
```ts
|
|
411
|
+
const { blobId } = await client.walrus.writeBlob({
|
|
412
|
+
blob: file,
|
|
413
|
+
deletable: true,
|
|
414
|
+
epochs: 3,
|
|
415
|
+
signer: keypair,
|
|
416
|
+
onStep: (step) => db.save(fileId, step),
|
|
417
|
+
resume: await db.load(fileId), // pass a previously saved step to resume
|
|
418
|
+
});
|
|
419
|
+
```
|
|
385
420
|
|
|
386
421
|
## Error handling
|
|
387
422
|
|
|
388
423
|
The SDK exports all the error classes for different types of errors that can be thrown. Walrus is a
|
|
389
|
-
fault-tolerant distributed system
|
|
390
|
-
changes
|
|
391
|
-
|
|
424
|
+
fault-tolerant distributed system where many types of errors can be recovered from. During epoch
|
|
425
|
+
changes, the data cached in the `WalrusClient` can become invalid. Errors that result from this
|
|
426
|
+
situation extend the `RetryableWalrusClientError` class.
|
|
392
427
|
|
|
393
|
-
You can check for these errors
|
|
428
|
+
You can check for these errors and reset the client before retrying:
|
|
394
429
|
|
|
395
430
|
```ts
|
|
396
431
|
if (error instanceof RetryableWalrusClientError) {
|
|
@@ -400,25 +435,25 @@ if (error instanceof RetryableWalrusClientError) {
|
|
|
400
435
|
}
|
|
401
436
|
```
|
|
402
437
|
|
|
403
|
-
`RetryableWalrusClientError` are not guaranteed to succeed after resetting the client and
|
|
404
|
-
but this pattern
|
|
438
|
+
`RetryableWalrusClientError` errors are not guaranteed to succeed after resetting the client and
|
|
439
|
+
retrying, but this pattern handles some edge cases.
|
|
405
440
|
|
|
406
|
-
High
|
|
407
|
-
|
|
441
|
+
High-level methods like `readBlob` already handle various error cases and automatically retry when
|
|
442
|
+
encountering these errors, as well as handling cases where only a subset of nodes need to respond
|
|
408
443
|
successfully to read or publish a blob.
|
|
409
444
|
|
|
410
|
-
When using the lower
|
|
411
|
-
|
|
412
|
-
|
|
445
|
+
When using the lower-level methods to build your own read or publish flows, understand the number of
|
|
446
|
+
shards and slivers that need to be successfully written or read for your operation to succeed.
|
|
447
|
+
Gracefully handle cases where some nodes might be in a bad state.
|
|
413
448
|
|
|
414
449
|
### Network errors
|
|
415
450
|
|
|
416
|
-
Walrus
|
|
417
|
-
|
|
418
|
-
challenging
|
|
451
|
+
Walrus handles some nodes being down, and the SDK only throws errors when it cannot read from or
|
|
452
|
+
write to enough storage nodes. When troubleshooting problems, figuring out what went wrong can be
|
|
453
|
+
challenging because you do not see all the individual network errors.
|
|
419
454
|
|
|
420
|
-
|
|
421
|
-
|
|
455
|
+
Pass an `onError` option in the `storageNodeClientOptions` to get the individual errors from failed
|
|
456
|
+
requests:
|
|
422
457
|
|
|
423
458
|
```ts
|
|
424
459
|
const client = new SuiGrpcClient({
|
|
@@ -435,16 +470,14 @@ const client = new SuiGrpcClient({
|
|
|
435
470
|
|
|
436
471
|
## Configuring network requests
|
|
437
472
|
|
|
438
|
-
Reading and writing blobs directly from storage nodes requires
|
|
439
|
-
|
|
440
|
-
|
|
473
|
+
Reading and writing blobs directly from storage nodes requires many requests. The Walrus SDK issues
|
|
474
|
+
all requests needed to complete these operations, but does not handle all the complexities a robust
|
|
475
|
+
aggregator or publisher might encounter.
|
|
441
476
|
|
|
442
|
-
By default, all requests
|
|
443
|
-
in.
|
|
477
|
+
By default, all requests use the global `fetch` for whatever runtime the SDK runs in.
|
|
444
478
|
|
|
445
|
-
This
|
|
446
|
-
|
|
447
|
-
`fetch` method:
|
|
479
|
+
This does not impose any limitations on concurrency, and is subject to default timeouts and behavior
|
|
480
|
+
defined by your runtime. To customize how requests are made, provide a custom `fetch` method:
|
|
448
481
|
|
|
449
482
|
```ts
|
|
450
483
|
const client = new SuiGrpcClient({
|
|
@@ -468,15 +501,15 @@ const client = new SuiGrpcClient({
|
|
|
468
501
|
);
|
|
469
502
|
```
|
|
470
503
|
|
|
471
|
-
## Loading the
|
|
504
|
+
## Loading the WASM module in Vite or client-side apps
|
|
472
505
|
|
|
473
|
-
The
|
|
474
|
-
some bundlers this
|
|
506
|
+
The Walrus SDK requires WASM bindings to encode and decode blobs. When running in Node.js or Bun,
|
|
507
|
+
and with some bundlers, this works without any additional configuration.
|
|
475
508
|
|
|
476
|
-
In some cases you
|
|
509
|
+
In some cases, you might need to manually specify where the SDK loads the WASM bindings from.
|
|
477
510
|
|
|
478
|
-
In
|
|
479
|
-
|
|
511
|
+
In Vite, get the URL for the WASM bindings by importing the WASM file with a `?url` suffix, then
|
|
512
|
+
pass it into the Walrus client:
|
|
480
513
|
|
|
481
514
|
```ts
|
|
482
515
|
const client = new SuiGrpcClient({
|
|
@@ -489,8 +522,8 @@ const client = new SuiGrpcClient({
|
|
|
489
522
|
);
|
|
490
523
|
```
|
|
491
524
|
|
|
492
|
-
If you are unable to get a
|
|
493
|
-
the
|
|
525
|
+
If you are unable to get a URL for the WASM file in your bundler or build system, you can self-host
|
|
526
|
+
the WASM bindings or load them from a CDN:
|
|
494
527
|
|
|
495
528
|
```ts
|
|
496
529
|
const client = new SuiGrpcClient({
|
|
@@ -503,8 +536,8 @@ const client = new SuiGrpcClient({
|
|
|
503
536
|
);
|
|
504
537
|
```
|
|
505
538
|
|
|
506
|
-
In
|
|
507
|
-
|
|
539
|
+
In Next.js, when using Walrus in API routes, you might need to tell Next.js to skip bundling for the
|
|
540
|
+
Walrus packages:
|
|
508
541
|
|
|
509
542
|
```ts
|
|
510
543
|
// next.config.ts
|
|
@@ -513,9 +546,21 @@ const nextConfig: NextConfig = {
|
|
|
513
546
|
};
|
|
514
547
|
```
|
|
515
548
|
|
|
516
|
-
## Known fetch limitations
|
|
549
|
+
## Known fetch limitations
|
|
550
|
+
|
|
551
|
+
- Some nodes can be slow to respond. When running in Node.js, the default `connectTimeout` is 10
|
|
552
|
+
seconds and can cause request timeouts.
|
|
553
|
+
- In Bun, the `abort` signal stops requests from responding, but the requests still wait for
|
|
554
|
+
completion before their promises reject.
|
|
517
555
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
556
|
+
## Full API
|
|
557
|
+
|
|
558
|
+
For a complete overview of the available methods on the `WalrusClient`, reference the
|
|
559
|
+
[TypeDocs](/typedoc/classes/_mysten_walrus.WalrusClient.html).
|
|
560
|
+
|
|
561
|
+
## Examples
|
|
562
|
+
|
|
563
|
+
There are a number of
|
|
564
|
+
[examples you can reference](https://github.com/MystenLabs/ts-sdks/tree/main/packages/walrus/examples)
|
|
565
|
+
in the `ts-sdks` repository that show things like building aggregators and publishers with the
|
|
566
|
+
Walrus SDK.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten/walrus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Walrus SDK",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,23 +30,23 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://sdk.mystenlabs.com/walrus",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@hono/node-server": "^1.19.
|
|
33
|
+
"@hono/node-server": "^1.19.11",
|
|
34
34
|
"@tanstack/react-query": "^5.90.16",
|
|
35
35
|
"@types/node": "^25.0.8",
|
|
36
36
|
"@types/react": "^19.2.8",
|
|
37
37
|
"@types/react-dom": "^19.2.3",
|
|
38
38
|
"@vitejs/plugin-react": "^5.1.2",
|
|
39
|
-
"hono": "^4.12.
|
|
39
|
+
"hono": "^4.12.8",
|
|
40
40
|
"react": "^19.2.3",
|
|
41
41
|
"react-dom": "^19.2.3",
|
|
42
42
|
"typescript": "^5.9.3",
|
|
43
|
-
"undici": "^7.
|
|
44
|
-
"vite": "^
|
|
43
|
+
"undici": "^7.24.4",
|
|
44
|
+
"vite": "^8.0.5",
|
|
45
45
|
"vitest": "^4.0.17",
|
|
46
|
-
"@mysten/codegen": "^0.8.
|
|
47
|
-
"@mysten/dapp-kit-core": "^1.
|
|
46
|
+
"@mysten/codegen": "^0.8.4",
|
|
47
|
+
"@mysten/dapp-kit-core": "^1.3.0",
|
|
48
48
|
"@mysten/dapp-kit-react": "^2.0.1",
|
|
49
|
-
"@mysten/sui": "^2.
|
|
49
|
+
"@mysten/sui": "^2.15.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"dataloader": "^2.2.3",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@mysten/walrus-wasm": "^0.2.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@mysten/sui": "^2.
|
|
58
|
+
"@mysten/sui": "^2.15.0"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|