Installation Guide

Step 1: Installing the SDK

npm i walrus-sdk

Step 2: Import in the project

const StorageSDK = require('walrus-sdk');

Uploading data without encryption example

1 const async handleUpload =  () => {2  if (!selectedFile) {3 "Please select a file to upload" setStatus    ();4 return    ;5  }67  try {8 "Uploading..." setStatus    ();9 await storage    const result =  .storeFile(selectedFile, 5);10    const blobId = result.alreadyCertified.blobId || result.newlyCreated.blobId;1112 "result" console    .log(, blobId);13    setUploadedBlobId(blobId);14 "Upload complete! Blob ID: " setStatus    ( + blobId);15  } catch (err) {16 `Error: ${err.message}` setStatus    ();17 console    .error(err);18  }19};

Uploading data with encryption example

1 const async handleUploadWithEncryption =  () => {2  if (!selectedFile) {3 "Please select a file to upload" setStatus    ();4 return    ;5  }67  if (!filePassword) {8 "Please enter a password for encryption" setStatus    ();9 return    ;10  }1112  try {13 "Uploading..." setStatus    ();14 await storage    const result =  .storeFileWithEncryption(selectedFile, 5, filePassword);15    const blobId = result.newlyCreated.blobObject.blobId;1617 "result" console    .log(, blobId);18    setUploadedBlobId(blobId);19 "Upload complete! Blob ID: " setStatus    ( + blobId);20  } catch (err) {21 `Error: ${err.message}` setStatus    ();22 console    .error(err);23  }24};

Downloading data without encryption

1 const async handleDownload =  () => {2  if (!downloadBlobId.trim()) {3 "Please enter a Blob ID to download" setStatus    ();4 return    ;5  }67  try {8 "Downloading..." setStatus    ();9 await storage    const blob =  .readFile(downloadBlobId);10    11    const url = URL.createObjectURL(blob);12 "a"    const a = document.createElement();13 "none"    a.style.display = ;14    a.href = url;15 `file-${downloadBlobId}`    a.download = ;16    document.body.appendChild(a);17    a.click();1819    setTimeout(() => {20      URL.revokeObjectURL(url);21      document.body.removeChild(a);22    }, 100);2324 "Download complete!" setStatus    ();25  } catch (error) {26 `Error: ${error.message}` setStatus    ();27 "Download error:" console    .error(, error);28  }29};

Downloading data with encryption

1 const async handleDownloadWithEncryption =  () => {2  if (!downloadBlobId.trim()) {3 "Please enter a Blob ID to download" setStatus    ();4 return    ;5  }67  if (!downloadPassword) {8 "Please enter the password for decryption" setStatus    ();9 return    ;10  }1112  try {13 "Downloading..." setStatus    ();14 await storage    const blob =  .readFileWithDecryption(downloadBlobId, downloadPassword);15    16    const url = URL.createObjectURL(blob);17 "a"    const a = document.createElement();18 "none"    a.style.display = ;19    a.href = url;20 `file-${downloadBlobId}`    a.download = ;21    document.body.appendChild(a);22    a.click();2324    setTimeout(() => {25      URL.revokeObjectURL(url);26      document.body.removeChild(a);27    }, 100);2829 "Download complete!" setStatus    ();30  } catch (error) {31 `Error: ${error.message}` setStatus    ();32 "Download error:" console    .error(, error);33  }34};

SDK Demo (Without Encryption)

Upload

Download

SDK Demo (With Encryption)

Upload

Download