Skip to content

Commit a83d4a5

Browse files
authored
Update walrus docs and examples (#172)
* Update walrus docs and examples * ignore mainnet script
1 parent 7095f9e commit a83d4a5

File tree

13 files changed

+63
-39
lines changed

13 files changed

+63
-39
lines changed

.changeset/full-facts-rescue.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mysten/walrus': patch
3+
---
4+
5+
update readme

packages/docs/content/walrus/index.mdx

-9
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ const walrusClient = new WalrusClient({
4242
});
4343
```
4444

45-
Walrus `testnet` nodes currently use self-signed certificates. Until all nodes are updated to use
46-
valid certificates, you may need to configure your environment to ignore certificate errors.
47-
48-
In node this can be done though an environment variable:
49-
50-
```ts
51-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
52-
```
53-
5445
For some environments you may need to customize how data is fetched:
5546

5647
```ts

packages/walrus/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples/mainnet.ts

packages/walrus/README.md

-9
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ const walrusClient = new WalrusClient({
4040
});
4141
```
4242

43-
Walrus `testnet` nodes currently use self-signed certificates. Until all nodes are updated to use
44-
valid certificates, you may need to configure your environment to ignore certificate errors.
45-
46-
In node this can be done though an environment variable:
47-
48-
```ts
49-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
50-
```
51-
5243
For some environments you may need to customize how data is fetched:
5344

5445
```ts

packages/walrus/examples/aggregator/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { Hono } from 'hono';
77

88
import { BlobBlockedError, BlobNotCertifiedError, WalrusClient } from '../../src/index.js';
99

10-
/** @ts-ignore */
11-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
12-
1310
const app = new Hono();
1411

1512
const suiClient = new SuiClient({

packages/walrus/examples/attributes/index.ts renamed to packages/walrus/examples/basics/attributes.ts

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
66
import { WalrusClient } from '../../src/client.js';
77
import { getFundedKeypair } from '../funded-keypair.js';
88

9-
/** @ts-ignore */
10-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
11-
129
const suiClient = new SuiClient({
1310
url: getFullnodeUrl('testnet'),
1411
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
5+
import { Agent, setGlobalDispatcher } from 'undici';
6+
7+
import { WalrusClient } from '../../src/client.js';
8+
import { getFundedKeypair } from '../funded-keypair.js';
9+
10+
// Node connect timeout is 10 seconds, and walrus nodes can be slow to respond
11+
setGlobalDispatcher(
12+
new Agent({
13+
connectTimeout: 60_000,
14+
connect: { timeout: 60_000 },
15+
}),
16+
);
17+
18+
const suiClient = new SuiClient({
19+
url: getFullnodeUrl('testnet'),
20+
});
21+
22+
const walrusClient = new WalrusClient({
23+
network: 'testnet',
24+
suiClient,
25+
storageNodeClientOptions: {
26+
timeout: 60_000,
27+
},
28+
});
29+
30+
async function uploadFile() {
31+
const keypair = await getFundedKeypair();
32+
33+
const file = new TextEncoder().encode('Hello from the TS SDK!!!\n');
34+
35+
const { blobObject } = await walrusClient.writeBlob({
36+
blob: file,
37+
deletable: true,
38+
epochs: 3,
39+
signer: keypair,
40+
});
41+
42+
console.log('created blob', blobObject.id.id);
43+
44+
await walrusClient.deleteBlob({ blobObjectId: blobObject.id.id });
45+
46+
console.log('deleted blob', blobObject.id.id);
47+
}
48+
49+
uploadFile().catch(console.error);

packages/walrus/examples/basics/read-blob.ts

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
55

66
import { WalrusClient } from '../../src/client.js';
77

8-
/** @ts-ignore */
9-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
10-
118
const suiClient = new SuiClient({
129
url: getFullnodeUrl('testnet'),
1310
});

packages/walrus/examples/basics/write-blob.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ setGlobalDispatcher(
1515
}),
1616
);
1717

18-
/** @ts-ignore */
19-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
20-
2118
const suiClient = new SuiClient({
2219
url: getFullnodeUrl('testnet'),
2320
});
@@ -37,7 +34,7 @@ async function uploadFile() {
3734

3835
const { blobId } = await walrusClient.writeBlob({
3936
blob: file,
40-
deletable: true,
37+
deletable: false,
4138
epochs: 3,
4239
signer: keypair,
4340
});

packages/walrus/examples/funded-keypair.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function getFundedKeypair() {
3232

3333
const walBalance = await suiClient.getBalance({
3434
owner: keypair.toSuiAddress(),
35-
coinType: `0x8190b041122eb492bf63cb464476bd68c6b7e570a4079645a8b28732b6197a82::wal::WAL`,
35+
coinType: `0x8270feb7375eee355e64fdb69c50abb6b5f9393a722883c1cf45f8e26048810a::wal::WAL`,
3636
});
3737
console.log('wal balance:', walBalance.totalBalance);
3838

packages/walrus/examples/publisher/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import { Hono } from 'hono';
88
import { WalrusClient } from '../../src/index.js';
99
import { getFundedKeypair } from '../funded-keypair.js';
1010

11-
/** @ts-ignore */
12-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
13-
1411
const suiClient = new SuiClient({
1512
url: getFullnodeUrl('testnet'),
1613
});

packages/walrus/examples/write-from-wallet/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ export function FileUpload() {
5151
throw new Error('Failed to register blob');
5252
}
5353

54+
const blobType = await walrusClient.getBlobType();
55+
5456
const blobObject = objectChanges?.find(
55-
(change) => change.type === 'created' && change.objectType === walrusClient.blobType,
57+
(change) => change.type === 'created' && change.objectType === blobType,
5658
);
5759

5860
if (!blobObject || blobObject.type !== 'created') {

packages/walrus/src/client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class WalrusClient {
158158
});
159159

160160
/** The Move type for a Blob object */
161-
#getBlobType = this.#memo.create('getBlobType', async () => {
161+
getBlobType = this.#memo.create('getBlobType', async () => {
162162
return `${await this.#getPackageId()}::blob::Blob`;
163163
});
164164

@@ -700,7 +700,7 @@ export class WalrusClient {
700700
...options,
701701
owner: options.transaction?.getData().sender ?? signer.toSuiAddress(),
702702
});
703-
const blobType = await this.#getBlobType();
703+
const blobType = await this.getBlobType();
704704

705705
const { digest, effects } = await this.#executeTransaction(
706706
transaction,
@@ -820,7 +820,7 @@ export class WalrusClient {
820820
...options,
821821
owner: options.owner ?? options.transaction?.getData().sender ?? signer.toSuiAddress(),
822822
});
823-
const blobType = await this.#getBlobType();
823+
const blobType = await this.getBlobType();
824824
const { digest, effects } = await this.#executeTransaction(
825825
transaction,
826826
signer,

0 commit comments

Comments
 (0)