@mysten/walrus 1.1.3 → 1.1.5
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
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @mysten/walrus
|
|
2
2
|
|
|
3
|
+
## 1.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9e067cf: Validate the new per-package release flow end-to-end across every public @mysten package.
|
|
8
|
+
No functional changes — empty patch bump to force the orchestrator to dispatch every
|
|
9
|
+
release-<pkg>.yml workflow with `dry_run=false` so each package publishes via OIDC trusted
|
|
10
|
+
publishing.
|
|
11
|
+
- Updated dependencies [9e067cf]
|
|
12
|
+
- @mysten/bcs@2.0.4
|
|
13
|
+
- @mysten/sui@2.16.1
|
|
14
|
+
- @mysten/utils@0.3.2
|
|
15
|
+
- @mysten/walrus-wasm@0.2.1
|
|
16
|
+
|
|
17
|
+
## 1.1.4
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- bb8d26a: Fix three latent type errors in the generated `utils/index.ts` that surfaced for
|
|
22
|
+
consumers with `noUncheckedIndexedAccess: true`:
|
|
23
|
+
- `getPureBcsSchema(structTag.typeParams[0])` passed `TypeTag | undefined` to a parameter typed
|
|
24
|
+
`string | TypeTag`. Now null-checks the inner tag before passing it.
|
|
25
|
+
- `argTypes[i]` was redundantly re-indexed inside a `for…of entries()` loop, returning
|
|
26
|
+
`string | null | undefined` and being passed back to `getPureBcsSchema`. Switched to the loop
|
|
27
|
+
variable, which is `string | null`.
|
|
28
|
+
- `MoveStruct.get()` returned the destructured `[res]` from `getMany([objectId])` without
|
|
29
|
+
asserting it was defined. Now throws if no object was returned.
|
|
30
|
+
|
|
31
|
+
The codegen test suite gained a `tsc`-based check that compiles the generated `utils/index.ts`
|
|
32
|
+
under strict + `noUncheckedIndexedAccess`, so embedded-template type bugs are caught before
|
|
33
|
+
release rather than by downstream consumers.
|
|
34
|
+
|
|
35
|
+
All consumer packages (`payment-kit`, `pas`, `walrus`, `suins`, `deepbook-v3`, `kiosk`) have been
|
|
36
|
+
regenerated with the fix.
|
|
37
|
+
|
|
3
38
|
## 1.1.3
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/contracts/utils/index.ts"],"mappings":";;;;;KAkBY,UAAA,iBAA2B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC1D,cAAA,CAAe,gBAAA,CAAiB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAE1C,cAAA,iBAA+B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC9D,cAAA,CAAe,iBAAA,CAAkB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,cAyI1C,UAAA,WACF,MAAA,SAAe,OAAA,oDAEhB,SAAA,CAAU,CAAA,EAAG,IAAA;EAChB,GAAA,iBAAoB,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IAC7C,QAAA;IAAA,GACG;EAAA,GACD,UAAA,CAAW,OAAA,IAAW,OAAA,CACxB,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/contracts/utils/index.ts"],"mappings":";;;;;KAkBY,UAAA,iBAA2B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC1D,cAAA,CAAe,gBAAA,CAAiB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,KAE1C,cAAA,iBAA+B,IAAA,CAAK,cAAA,CAAe,aAAA,qBAC9D,cAAA,CAAe,iBAAA,CAAkB,OAAA;EAAa,MAAA,EAAQ,iBAAA;AAAA;AAAA,cAyI1C,UAAA,WACF,MAAA,SAAe,OAAA,oDAEhB,SAAA,CAAU,CAAA,EAAG,IAAA;EAChB,GAAA,iBAAoB,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IAC7C,QAAA;IAAA,GACG;EAAA,GACD,UAAA,CAAW,OAAA,IAAW,OAAA,CACxB,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;EAeZ,OAAA,iBAAwB,IAAA,CAAK,cAAA,CAAe,aAAA,2BAAA,CAAA;IACjD,MAAA;IAAA,GACG;EAAA,GACD,cAAA,CAAe,OAAA,IAAW,OAAA,CAC5B,KAAA,CACC,cAAA,CAAe,MAAA,CAAO,OAAA;IAAY,OAAA;IAAe,IAAA;EAAA;IAChD,IAAA,EAAM,SAAA,CAAU,CAAA;EAAA;AAAA"}
|
|
@@ -24,7 +24,8 @@ function getPureBcsSchema(typeTag) {
|
|
|
24
24
|
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
25
25
|
if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") return bcs.String;
|
|
26
26
|
if (structTag.module === "option" && structTag.name === "Option") {
|
|
27
|
-
const
|
|
27
|
+
const inner = structTag.typeParams[0];
|
|
28
|
+
const type = inner ? getPureBcsSchema(inner) : null;
|
|
28
29
|
return type ? bcs.option(type) : null;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -37,7 +38,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
37
38
|
if (parameterNames && argLen !== parameterNames.length) throw new Error(`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`);
|
|
38
39
|
const normalizedArgs = [];
|
|
39
40
|
let index = 0;
|
|
40
|
-
for (const
|
|
41
|
+
for (const argType of argTypes) {
|
|
41
42
|
if (argType === "0x2::clock::Clock") {
|
|
42
43
|
normalizedArgs.push((tx) => tx.object.clock());
|
|
43
44
|
continue;
|
|
@@ -69,8 +70,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
69
70
|
normalizedArgs.push(arg);
|
|
70
71
|
continue;
|
|
71
72
|
}
|
|
72
|
-
const
|
|
73
|
-
const bcsType = type === null ? null : getPureBcsSchema(type);
|
|
73
|
+
const bcsType = argType === null ? null : getPureBcsSchema(argType);
|
|
74
74
|
if (bcsType) {
|
|
75
75
|
const bytes = bcsType.serialize(arg);
|
|
76
76
|
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
@@ -80,7 +80,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
80
80
|
normalizedArgs.push((tx) => tx.object(arg));
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
|
-
throw new Error(`Invalid argument ${stringify(arg)} for type ${
|
|
83
|
+
throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
|
|
84
84
|
}
|
|
85
85
|
return normalizedArgs;
|
|
86
86
|
}
|
|
@@ -90,6 +90,7 @@ var MoveStruct = class extends BcsStruct {
|
|
|
90
90
|
...options,
|
|
91
91
|
objectIds: [objectId]
|
|
92
92
|
});
|
|
93
|
+
if (!res) throw new Error(`No object found for id ${objectId}`);
|
|
93
94
|
return res;
|
|
94
95
|
}
|
|
95
96
|
async getMany({ client, ...options }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["val"],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["val"],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\tasync get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten/walrus",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Walrus SDK",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,25 +42,21 @@
|
|
|
42
42
|
"typescript": "^5.9.3",
|
|
43
43
|
"undici": "^7.24.4",
|
|
44
44
|
"vite": "^8.0.5",
|
|
45
|
-
"vitest": "^4.0.17"
|
|
46
|
-
"@mysten/codegen": "^0.10.0",
|
|
47
|
-
"@mysten/dapp-kit-core": "^1.3.0",
|
|
48
|
-
"@mysten/dapp-kit-react": "^2.0.1",
|
|
49
|
-
"@mysten/sui": "^2.16.0"
|
|
45
|
+
"vitest": "^4.0.17"
|
|
50
46
|
},
|
|
51
47
|
"dependencies": {
|
|
52
48
|
"dataloader": "^2.2.3",
|
|
53
|
-
"@mysten/
|
|
54
|
-
"@mysten/
|
|
55
|
-
"@mysten/walrus-wasm": "^0.2.
|
|
49
|
+
"@mysten/utils": "^0.3.2",
|
|
50
|
+
"@mysten/bcs": "^2.0.4",
|
|
51
|
+
"@mysten/walrus-wasm": "^0.2.1"
|
|
56
52
|
},
|
|
57
53
|
"peerDependencies": {
|
|
58
|
-
"@mysten/sui": "^2.16.
|
|
54
|
+
"@mysten/sui": "^2.16.1"
|
|
59
55
|
},
|
|
60
56
|
"scripts": {
|
|
61
57
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
62
58
|
"build": "rm -rf dist && tsc --noEmit && tsdown",
|
|
63
|
-
"build:docs": "
|
|
59
|
+
"build:docs": "node ../docs/scripts/build-docs.ts",
|
|
64
60
|
"test": "pnpm test:examples && NODE_OPTIONS='--expose-gc' vitest run",
|
|
65
61
|
"test:examples": "tsc --project examples/tsconfig.json --noEmit",
|
|
66
62
|
"codegen": "sui-ts-codegen generate && pnpm lint:fix",
|
package/docs/index.md
DELETED
|
@@ -1,566 +0,0 @@
|
|
|
1
|
-
# Walrus SDK
|
|
2
|
-
|
|
3
|
-
> Store and retrieve blobs on Walrus decentralized storage using the TypeScript SDK.
|
|
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
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash npm2yarn
|
|
20
|
-
npm install --save @mysten/walrus @mysten/sui
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Setup
|
|
24
|
-
|
|
25
|
-
To use the Walrus SDK, you need to create a client from the TypeScript SDK and extend it with the
|
|
26
|
-
Walrus SDK.
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
const client = new SuiGrpcClient({
|
|
30
|
-
network: 'testnet',
|
|
31
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
32
|
-
}).$extend(walrus());
|
|
33
|
-
```
|
|
34
|
-
|
|
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.
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
const client = new SuiGrpcClient({
|
|
41
|
-
network: 'testnet',
|
|
42
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
43
|
-
}).$extend(
|
|
44
|
-
walrus({
|
|
45
|
-
packageConfig: {
|
|
46
|
-
systemObjectId: '0x98ebc47370603fe81d9e15491b2f1443d619d1dab720d586e429ed233e1255c1',
|
|
47
|
-
stakingPoolId: '0x20266a17b4f1a216727f3eef5772f8d486a9e3b5e319af80a5b75809c035561d',
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Some environments require you to customize how data is fetched:
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
const client = new SuiGrpcClient({
|
|
57
|
-
network: 'testnet',
|
|
58
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
59
|
-
}).$extend(
|
|
60
|
-
walrus({
|
|
61
|
-
storageNodeClientOptions: {
|
|
62
|
-
fetch: (url, options) => {
|
|
63
|
-
console.log('fetching', url);
|
|
64
|
-
return fetch(url, options);
|
|
65
|
-
},
|
|
66
|
-
timeout: 60_000,
|
|
67
|
-
},
|
|
68
|
-
}),
|
|
69
|
-
);
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
You can use this approach to implement a fetch function with custom timeouts, rate limits, retry
|
|
73
|
-
logic, or any other desired behavior.
|
|
74
|
-
|
|
75
|
-
## `WalrusFile` API
|
|
76
|
-
|
|
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.
|
|
80
|
-
|
|
81
|
-
### Reading files
|
|
82
|
-
|
|
83
|
-
To read files, use the `getFiles` method. This method accepts both blob IDs and quilt IDs, and
|
|
84
|
-
returns a `WalrusFile`.
|
|
85
|
-
|
|
86
|
-
Read files in batches when possible, which allows the client to be more efficient when loading
|
|
87
|
-
multiple files from the same quilt.
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
const [file1, file2] = await client.walrus.getFiles({ ids: [anyBlobId, orQuiltId] });
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
A `WalrusFile` works like a `Response` object from the `fetch` API:
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
// get contents as a Uint8Array
|
|
97
|
-
const bytes = await file1.bytes();
|
|
98
|
-
// Parse the contents as a `utf-8` string
|
|
99
|
-
const text = await file1.text();
|
|
100
|
-
// Parse the contents as JSON
|
|
101
|
-
const json = await file2.json();
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
A `WalrusFile` might also have `identifier` and `tags` properties if the file was stored in a quilt.
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
const identifier: string | null = await file1.getIdentifier();
|
|
108
|
-
const tags: Record<string, string> = await file1.getTags();
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
#### `WalrusBlob`
|
|
112
|
-
|
|
113
|
-
You can also get a `WalrusBlob` instead of a `WalrusFile` if you have the `blobId`:
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
const blob = await client.walrus.getBlob({ blobId });
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
If the blob is a quilt, you can read the files in the quilt:
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
// Get all files:
|
|
123
|
-
const files = await blob.files();
|
|
124
|
-
// Get files by identifier
|
|
125
|
-
const [readme] = await blob.files({ identifiers: ['README.md'] });
|
|
126
|
-
// Get files by tag
|
|
127
|
-
const textFiles = await blob.files({ tags: [{ 'content-type': 'text/plain' }] });
|
|
128
|
-
// Get files by quilt id
|
|
129
|
-
const filesById = await blob.files({ ids: [quiltID] });
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Writing files
|
|
133
|
-
|
|
134
|
-
You can also construct a `WalrusFile` from a `Uint8Array`, `Blob`, or a `string`, which you can then
|
|
135
|
-
store on Walrus:
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
const file1 = WalrusFile.from({
|
|
139
|
-
contents: new Uint8Array([1, 2, 3]),
|
|
140
|
-
identifier: 'file1.bin',
|
|
141
|
-
});
|
|
142
|
-
const file2 = WalrusFile.from({
|
|
143
|
-
contents: new Blob([new Uint8Array([1, 2, 3])]),
|
|
144
|
-
identifier: 'file2.bin',
|
|
145
|
-
});
|
|
146
|
-
const file3 = WalrusFile.from({
|
|
147
|
-
contents: new TextEncoder().encode('Hello from the TS SDK!!!\n'),
|
|
148
|
-
identifier: 'README.md',
|
|
149
|
-
tags: {
|
|
150
|
-
'content-type': 'text/plain',
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
After you have your files, use the `writeFiles` method to write them to Walrus.
|
|
156
|
-
|
|
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.
|
|
162
|
-
|
|
163
|
-
The exact costs depend on the size of the blobs, as well as the current gas and storage prices.
|
|
164
|
-
|
|
165
|
-
```ts
|
|
166
|
-
const results: {
|
|
167
|
-
id: string;
|
|
168
|
-
blobId: string;
|
|
169
|
-
blobObject: Blob.$inferType;
|
|
170
|
-
}[] = await client.walrus.writeFiles({
|
|
171
|
-
files: [file1, file2, file3],
|
|
172
|
-
epochs: 3,
|
|
173
|
-
deletable: true,
|
|
174
|
-
signer: keypair,
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
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.
|
|
180
|
-
|
|
181
|
-
The current quilt encoding is less efficient for single files, so writing multiple files together is
|
|
182
|
-
recommended when possible. Writing raw blobs directly is also possible using the `writeBlob` API
|
|
183
|
-
described below.
|
|
184
|
-
|
|
185
|
-
#### Writing files in browser environments
|
|
186
|
-
|
|
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.
|
|
190
|
-
|
|
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.
|
|
193
|
-
|
|
194
|
-
The `client.writeFilesFlow` method returns an object with a set of methods that break the write flow
|
|
195
|
-
into several smaller steps:
|
|
196
|
-
|
|
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.
|
|
202
|
-
|
|
203
|
-
The following simplified example shows the core API usage with separate user interactions:
|
|
204
|
-
|
|
205
|
-
```tsx
|
|
206
|
-
// Step 1: Create and encode the flow (can be done immediately when file is selected)
|
|
207
|
-
const flow = client.walrus.writeFilesFlow({
|
|
208
|
-
files: [
|
|
209
|
-
WalrusFile.from({
|
|
210
|
-
contents: new Uint8Array(fileData),
|
|
211
|
-
identifier: 'my-file.txt',
|
|
212
|
-
}),
|
|
213
|
-
],
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
await flow.encode();
|
|
217
|
-
|
|
218
|
-
// Step 2: Register the blob (triggered by user clicking a register button after the encode step)
|
|
219
|
-
async function handleRegister() {
|
|
220
|
-
const registerTx = flow.register({
|
|
221
|
-
epochs: 3,
|
|
222
|
-
owner: currentAccount.address,
|
|
223
|
-
deletable: true,
|
|
224
|
-
});
|
|
225
|
-
const result = await signAndExecuteTransaction({ transaction: registerTx });
|
|
226
|
-
|
|
227
|
-
// Check transaction status
|
|
228
|
-
if (result.$kind === 'FailedTransaction') {
|
|
229
|
-
throw new Error(`Registration failed: ${result.FailedTransaction.status.error?.message}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Step 3: Upload the data to storage nodes
|
|
233
|
-
// This can be done immediately after the register step, or as a separate step the user initiates
|
|
234
|
-
await flow.upload({ digest: result.Transaction.digest });
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Step 4: Certify the blob (triggered by user clicking a certify button after the blob is uploaded)
|
|
238
|
-
async function handleCertify() {
|
|
239
|
-
const certifyTx = flow.certify();
|
|
240
|
-
|
|
241
|
-
const result = await signAndExecuteTransaction({ transaction: certifyTx });
|
|
242
|
-
|
|
243
|
-
// Check transaction status
|
|
244
|
-
if (result.$kind === 'FailedTransaction') {
|
|
245
|
-
throw new Error(`Certification failed: ${result.FailedTransaction.status.error?.message}`);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Step 5: Get the new files
|
|
249
|
-
const files = await flow.listFiles();
|
|
250
|
-
console.log('Uploaded files', files);
|
|
251
|
-
}
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
This approach ensures that each transaction signing step is separated into different user
|
|
255
|
-
interactions, allowing wallet popups to work properly without being blocked by the browser.
|
|
256
|
-
|
|
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
|
|
297
|
-
|
|
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.
|
|
300
|
-
|
|
301
|
-
To use an upload relay, add the `uploadRelay` option when adding the Walrus extension:
|
|
302
|
-
|
|
303
|
-
```ts
|
|
304
|
-
const client = new SuiGrpcClient({
|
|
305
|
-
network: 'testnet',
|
|
306
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
307
|
-
}).$extend(
|
|
308
|
-
walrus({
|
|
309
|
-
uploadRelay: {
|
|
310
|
-
host: 'https://upload-relay.testnet.walrus.space',
|
|
311
|
-
sendTip: {
|
|
312
|
-
max: 1_000,
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
}),
|
|
316
|
-
);
|
|
317
|
-
```
|
|
318
|
-
|
|
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.
|
|
323
|
-
|
|
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.
|
|
327
|
-
|
|
328
|
-
### `const` tip
|
|
329
|
-
|
|
330
|
-
A `const` tip sends a fixed amount for each blob written to the upload relay.
|
|
331
|
-
|
|
332
|
-
```ts
|
|
333
|
-
const client = new SuiGrpcClient({
|
|
334
|
-
network: 'testnet',
|
|
335
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
336
|
-
}).$extend(
|
|
337
|
-
walrus({
|
|
338
|
-
uploadRelay: {
|
|
339
|
-
host: 'https://upload-relay.testnet.walrus.space',
|
|
340
|
-
sendTip: {
|
|
341
|
-
address: '0x123...',
|
|
342
|
-
kind: {
|
|
343
|
-
const: 105,
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
},
|
|
347
|
-
}),
|
|
348
|
-
);
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
### `linear` tip
|
|
352
|
-
|
|
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.
|
|
355
|
-
|
|
356
|
-
```ts
|
|
357
|
-
const client = new SuiGrpcClient({
|
|
358
|
-
network: 'testnet',
|
|
359
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
360
|
-
}).$extend(
|
|
361
|
-
walrus({
|
|
362
|
-
uploadRelay: {
|
|
363
|
-
host: 'https://upload-relay.testnet.walrus.space',
|
|
364
|
-
sendTip: {
|
|
365
|
-
address: '0x123...',
|
|
366
|
-
kind: {
|
|
367
|
-
linear: {
|
|
368
|
-
base: 105,
|
|
369
|
-
perEncodedKib: 10,
|
|
370
|
-
},
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
}),
|
|
375
|
-
);
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
## Interacting with blobs directly
|
|
379
|
-
|
|
380
|
-
If you do not want to use the `WalrusFile` abstractions, use the `readBlob` and `writeBlob` APIs
|
|
381
|
-
directly.
|
|
382
|
-
|
|
383
|
-
### Reading blobs
|
|
384
|
-
|
|
385
|
-
The `readBlob` method reads a blob given the `blobId` and returns a `Uint8Array` containing the blob
|
|
386
|
-
content:
|
|
387
|
-
|
|
388
|
-
```ts
|
|
389
|
-
const blob = await client.walrus.readBlob({ blobId });
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
### Writing blobs
|
|
393
|
-
|
|
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.
|
|
396
|
-
|
|
397
|
-
```ts
|
|
398
|
-
const file = new TextEncoder().encode('Hello from the TS SDK!!!\n');
|
|
399
|
-
|
|
400
|
-
const { blobId } = await client.walrus.writeBlob({
|
|
401
|
-
blob: file,
|
|
402
|
-
deletable: false,
|
|
403
|
-
epochs: 3,
|
|
404
|
-
signer: keypair,
|
|
405
|
-
});
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
`writeBlob` and `writeFiles` also support `onStep` and `resume` for crash-recoverable uploads:
|
|
409
|
-
|
|
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
|
-
```
|
|
420
|
-
|
|
421
|
-
## Error handling
|
|
422
|
-
|
|
423
|
-
The SDK exports all the error classes for different types of errors that can be thrown. Walrus is a
|
|
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.
|
|
427
|
-
|
|
428
|
-
You can check for these errors and reset the client before retrying:
|
|
429
|
-
|
|
430
|
-
```ts
|
|
431
|
-
if (error instanceof RetryableWalrusClientError) {
|
|
432
|
-
client.walrus.reset();
|
|
433
|
-
|
|
434
|
-
/* retry your operation */
|
|
435
|
-
}
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
`RetryableWalrusClientError` errors are not guaranteed to succeed after resetting the client and
|
|
439
|
-
retrying, but this pattern handles some edge cases.
|
|
440
|
-
|
|
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
|
|
443
|
-
successfully to read or publish a blob.
|
|
444
|
-
|
|
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.
|
|
448
|
-
|
|
449
|
-
### Network errors
|
|
450
|
-
|
|
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.
|
|
454
|
-
|
|
455
|
-
Pass an `onError` option in the `storageNodeClientOptions` to get the individual errors from failed
|
|
456
|
-
requests:
|
|
457
|
-
|
|
458
|
-
```ts
|
|
459
|
-
const client = new SuiGrpcClient({
|
|
460
|
-
network: 'testnet',
|
|
461
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
462
|
-
}).$extend(
|
|
463
|
-
walrus({
|
|
464
|
-
storageNodeClientOptions: {
|
|
465
|
-
onError: (error) => console.log(error),
|
|
466
|
-
},
|
|
467
|
-
}),
|
|
468
|
-
);
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
## Configuring network requests
|
|
472
|
-
|
|
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.
|
|
476
|
-
|
|
477
|
-
By default, all requests use the global `fetch` for whatever runtime the SDK runs in.
|
|
478
|
-
|
|
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:
|
|
481
|
-
|
|
482
|
-
```ts
|
|
483
|
-
const client = new SuiGrpcClient({
|
|
484
|
-
network: 'testnet',
|
|
485
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
486
|
-
}).$extend(
|
|
487
|
-
walrus({
|
|
488
|
-
storageNodeClientOptions: {
|
|
489
|
-
timeout: 60_000,
|
|
490
|
-
fetch: (url, init) => {
|
|
491
|
-
// Some casting may be required because undici types may not exactly match the @node/types types
|
|
492
|
-
return fetch(url as RequestInfo, {
|
|
493
|
-
...(init as RequestInit),
|
|
494
|
-
dispatcher: new Agent({
|
|
495
|
-
connectTimeout: 60_000,
|
|
496
|
-
}),
|
|
497
|
-
}) as unknown as Promise<Response>;
|
|
498
|
-
},
|
|
499
|
-
},
|
|
500
|
-
}),
|
|
501
|
-
);
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
## Loading the WASM module in Vite or client-side apps
|
|
505
|
-
|
|
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.
|
|
508
|
-
|
|
509
|
-
In some cases, you might need to manually specify where the SDK loads the WASM bindings from.
|
|
510
|
-
|
|
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:
|
|
513
|
-
|
|
514
|
-
```ts
|
|
515
|
-
const client = new SuiGrpcClient({
|
|
516
|
-
network: 'testnet',
|
|
517
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
518
|
-
}).$extend(
|
|
519
|
-
walrus({
|
|
520
|
-
wasmUrl: walrusWasmUrl,
|
|
521
|
-
}),
|
|
522
|
-
);
|
|
523
|
-
```
|
|
524
|
-
|
|
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:
|
|
527
|
-
|
|
528
|
-
```ts
|
|
529
|
-
const client = new SuiGrpcClient({
|
|
530
|
-
network: 'testnet',
|
|
531
|
-
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
532
|
-
}).$extend(
|
|
533
|
-
walrus({
|
|
534
|
-
wasmUrl: 'https://unpkg.com/@mysten/walrus-wasm@latest/web/walrus_wasm_bg.wasm',
|
|
535
|
-
}),
|
|
536
|
-
);
|
|
537
|
-
```
|
|
538
|
-
|
|
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:
|
|
541
|
-
|
|
542
|
-
```ts
|
|
543
|
-
// next.config.ts
|
|
544
|
-
const nextConfig: NextConfig = {
|
|
545
|
-
serverExternalPackages: ['@mysten/walrus', '@mysten/walrus-wasm'],
|
|
546
|
-
};
|
|
547
|
-
```
|
|
548
|
-
|
|
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.
|
|
555
|
-
|
|
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.
|