store_blob
Store data in decentralized storage using base64 encoding or file paths, with configurable retention periods through blockchain verification on the Sui network.
Instructions
Store a blob in Walrus decentralized storage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Base64 encoded data or file path to store | |
| epochs | No | Number of epochs to store the blob (default: 5) |
Implementation Reference
- src/index.ts:140-151 (handler)MCP tool handler for 'store_blob': parses arguments using StoreBlobSchema and delegates to walrusClient.storeBlob, returning JSON stringified resultcase 'store_blob': { const { data, epochs = 5 } = StoreBlobSchema.parse(args); const result = await walrusClient.storeBlob(data, epochs); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:30-33 (schema)Zod input schema for store_blob tool validationconst StoreBlobSchema = z.object({ data: z.string().describe('Base64 encoded data or file path to store'), epochs: z.number().optional().describe('Number of epochs to store the blob (default: 5)'), });
- src/index.ts:56-72 (registration)Registration of store_blob tool in the listTools response, including name, description, and input schemaname: 'store_blob', description: 'Store a blob in Walrus decentralized storage', inputSchema: { type: 'object', properties: { data: { type: 'string', description: 'Base64 encoded data or file path to store', }, epochs: { type: 'number', description: 'Number of epochs to store the blob (default: 5)', default: 5, }, }, required: ['data'], },
- src/walrus-client.ts:49-104 (helper)Core storeBlob implementation in WalrusClient: handles file paths or base64 data, publishes to Walrus publisher endpoint, parses response into BlobInfoasync storeBlob(data: string, epochs: number = 5): Promise<BlobInfo> { try { let blobData: Buffer; // Check if data is a file path or base64 encoded data if (data.startsWith('/') || data.startsWith('./') || data.startsWith('../')) { // It's a file path blobData = await fs.readFile(data); } else { // It's base64 encoded data blobData = Buffer.from(data, 'base64'); } const response = await this.httpClient.put( `${this.config.publisherUrl}/v1/store`, blobData, { headers: { 'Content-Type': 'application/octet-stream', }, params: { epochs: epochs.toString(), }, } ); if (response.data.newlyCreated) { return { blobId: response.data.newlyCreated.blobObject.blobId, size: response.data.newlyCreated.blobObject.size, encodedSize: response.data.newlyCreated.blobObject.encodedSize, storageId: response.data.newlyCreated.blobObject.id, certified: response.data.newlyCreated.resourceObject ? true : false, certifiedEpoch: response.data.newlyCreated.resourceObject?.storage?.startEpoch, endEpoch: response.data.newlyCreated.resourceObject?.storage?.endEpoch, }; } else if (response.data.alreadyCertified) { return { blobId: response.data.alreadyCertified.blobId, size: 0, // Size not provided for already certified blobs encodedSize: 0, storageId: response.data.alreadyCertified.blobId, certified: true, certifiedEpoch: response.data.alreadyCertified.certifiedEpoch, endEpoch: response.data.alreadyCertified.endEpoch, }; } throw new Error('Unexpected response format from Walrus publisher'); } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Failed to store blob: ${error.response?.data?.error || error.message}`); } throw new Error(`Failed to store blob: ${error instanceof Error ? error.message : String(error)}`); } }