npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@galliun/walrus-sdk

v1.0.0

Published

TypeScript SDK for Walrus API

Downloads

74

Readme

Walrus SDK Documentation

The Walrus SDK is a TypeScript library that provides an interface to interact with the Walrus storage system. It allows users to store and retrieve data using the Walrus Publisher and Aggregator.

Installation

To install the Walrus SDK, use npm:

npm install @galliun/walrus-sdk

Usage

First, import the WalrusSDK class:

import WalrusSDK from 'walrus-sdk';

Then, create an instance of the SDK:

const walrus = new WalrusSDK({
  aggregatorUrl: 'https://your-aggregator-url.com',
  publisherUrl: 'https://your-publisher-url.com'
});

If you don't provide URLs, the SDK will use default testnet URLs.

API Reference

Constructor

constructor(config: WalrusConfig = {})

Creates a new instance of the WalrusSDK.

  • config: An optional configuration object with the following properties:
    • aggregatorUrl: The URL of the Walrus aggregator (default: 'https://aggregator.walrus-testnet.walrus.space')
    • publisherUrl: The URL of the Walrus publisher (default: 'https://publisher.walrus-testnet.walrus.space')

Methods

store

async store(data: string | ArrayBuffer, options: StoreOptions = {}): Promise<StoreResponse>

Stores data in the Walrus network.

  • data: The data to store (string or ArrayBuffer)
  • options: An optional object with the following properties:
    • epochs: Number of epochs to store the data
    • force: Force storage even if the data already exists
    • deletable: Whether the data can be deleted

Returns a Promise that resolves to a StoreResponse object, which can be either a NewlyCreatedResponse or an AlreadyCertifiedResponse.

read

async read(blobId: string): Promise<string>

Reads data from the Walrus network and returns it as a string.

  • blobId: The ID of the blob to read

Returns a Promise that resolves to the data as a string.

readAsBuffer

async readAsBuffer(blobId: string): Promise<ArrayBuffer>

Reads data from the Walrus network and returns it as an ArrayBuffer.

  • blobId: The ID of the blob to read

Returns a Promise that resolves to the data as an ArrayBuffer.

readAsStream

async readAsStream(blobId: string): Promise<ReadableStream>

Reads data from the Walrus network and returns it as a ReadableStream.

  • blobId: The ID of the blob to read

Returns a Promise that resolves to a ReadableStream of the data.

Error Handling

The SDK throws errors in the following cases:

  1. If the Publisher URL is not set when calling store.
  2. If the Aggregator URL is not set when calling read, readAsBuffer, or readAsStream.
  3. If there's an HTTP error during any API call.
  4. If the response body is null when calling readAsStream.

Make sure to wrap your SDK calls in try-catch blocks to handle these errors appropriately.

Examples

Here's an example of how to use the Walrus SDK to store and retrieve data:

import WalrusSDK from 'walrus-sdk';

const walrus = new WalrusSDK();

async function storeAndRetrieveData() {
  try {
    // Store data
    const storeResponse = await walrus.store('Hello, Walrus!', { epochs: 5 });
    
    if ('newlyCreated' in storeResponse) {
      const blobId = storeResponse.newlyCreated.blobObject.blobId;
      console.log(`Data stored with Blob ID: ${blobId}`);
      
      // Retrieve data
      const retrievedData = await walrus.read(blobId);
      console.log(`Retrieved data: ${retrievedData}`);
    } else {
      console.log('Data was already certified:', storeResponse.alreadyCertified);
    }
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

storeAndRetrieveData();