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

tuskscript

v0.0.3

Published

Lightweight Walrus Client for Typescript

Downloads

25

Readme

tuskscript

tuskscript is a TypeScript-based npm package that simplifies development for the Walrus network. It provides an easy-to-use API for storing and retrieving data, allowing seamless integration with both Web2 and Web3 applications. Whether you are building decentralized apps (dApps) or traditional applications, TuskScript enables you to leverage the power of the Walrus network with minimal effort.

Installation

Use the package manager npm to install tuskscript.

npm i tuskscript

Usage

Below is a quick example of how to use TuskScript to store and retrieve data on the Walrus network.

Storing Data

Start by creating a new instance of WalrusClient. You can store any JavaScript object, and the API will return details about the stored blob. If the data is new, it returns a NewBlob. If the data has been previously stored, it returns an ExistingBlob.

import { 
  WalrusClient,
  NewBlob,
  ExistingBlob
} from "tuskscript";

const client = new WalrusClient();
// const publisher = "..."
// const aggregator = "...";
// const client = new WalrusClient(publisher, aggregator);

const data = {
  name: "Walrus",
  language: "Move",
  chain: "Sui",
};

// Store data as a new blob
const result: NewBlob = await client.store(data);
console.log(result);
/*
{
    newlyCreated: {
        blobObject: {
            id: '0xd3ee449b225ae4bfdd3f361982883b1f6312ab25a512a431bad99c87ff12c844',
            storedEpoch: 0,
            blobId: 'BmDTorm0NtVbVZcFXlQaKQ2xLiJ7HvxPuoIoE3hC0Pk',
            size: 49,
            erasureCodeType: 'RedStuff',
            certifiedEpoch: 0,
            storage: {}
        },
        encodedSize: 65023000,
        cost: 3175000
    }
}
*/

// Storing the same data again returns an ExistingBlob
const existingResult: ExistingBlob = await client.store(data);
console.log(existingResult);
/*
{
    alreadyCertified: {
        blobId: 'BmDTorm0NtVbVZcFXlQaKQ2xLiJ7HvxPuoIoE3hC0Pk',
        event: {
            txDigest: 'EW7pCYu7DNfPYpS5j3c8gVA2w3hNiP7dyYARbAxCSSbK',
            eventSeq: '0'
        },
        endEpoch: 1
    }
}
*/

Retrieving Data

You can retrieve stored data by its blobId. By default, data is retrieved as a Blob, but you can also parse it directly into TypeScript types.

import { WalrusClient } from "tuskscript";

const client = new WalrusClient();
const blobId = "BmDTorm0NtVbVZcFXlQaKQ2xLiJ7HvxPuoIoE3hC0Pk";

// Retrieve data as a Blob object
const blob: Blob = await client.retrieve(blobId);
const data = JSON.parse(await blob.text());
console.log(data);
/*
{
    "name": "Walrus",
    "language": "Move",
    "chain": "Sui"
}
*/

// Retrieve data directly as a JavaScript object
const directData = await client.retrieve(blobId, { asBlob: false });
console.log(directData);
/*
{
    "name": "Walrus",
    "language": "Move",
    "chain": "Sui"
}
*/

// Retrieve data with specified content type
const jsonBlob = await client.retrieve(blobId, { type: "application/json" });

Low-Level Services

If you need more granular control over the data storage and retrieval process, you can use the low-level store and retrieve functions:

import { store, retrieve } from "tuskscript";

const publisher = "...";
const aggregator = "...";

const data = {
  name: "Walrus",
  language: "Move",
  chain: "Sui",
};

// Store data with additional options
const result = await store({
  publisher,
  data,
  epoch: 5
});

// Retrieve data using low-level retrieval
const blobId = "BmDTorm0NtVbVZcFXlQaKQ2xLiJ7HvxPuoIoE3hC0Pk";
const retrievedData = await retrieve({
  aggregator,
  id: blobId,
});

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT