store_blob
Store base64-encoded data or files in Walrus decentralized storage for a specified number of epochs, enabling blockchain-verified data availability using 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 input args using Zod schema and calls walrusClient.storeBlob to store the blob, returning JSON result.case '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 schema for validating 'store_blob' tool input parameters.const 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:55-73 (registration)Tool registration in ListTools handler: defines name, description, and JSON inputSchema for 'store_blob'.{ name: '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 implementation of storeBlob in WalrusClient: handles file path or base64 data, makes HTTP PUT to Walrus publisher API to store the blob.async 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)}`); } }