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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@roochnetwork/rooch-sdk

v0.4.0

Published

Rooch SDK

Readme

Rooch TypeScript SDK

This is the Rooch TypeScript SDK built on the Rooch JSON RPC API. It provides utility classes and functions for applications to sign transactions and interact with the Rooch network.

WARNING: Note that we are still iterating on the RPC and SDK API before TestNet, therefore please expect frequent breaking changes in the short-term. We expect the API to stabilize after the upcoming TestNet launch.

Installation

npm i @roochnetwork/rooch-sdk

Connecting to Rooch Network

The SDK supports both HTTP and WebSocket connections. You can choose the appropriate transport based on your needs:

HTTP Connection (Default)

import { RoochClient, getRoochNodeUrl } from '@roochnetwork/rooch-sdk'

// create a client connected to testnet
const client = new RoochClient({
  url: getRoochNodeUrl('testnet'),
})

// get balances
await client.getBalances({
  owner: '',
})

WebSocket Connection

import { RoochClient, RoochWebSocketTransport, getRoochNodeUrl } from '@roochnetwork/rooch-sdk'

// Create WebSocket transport with custom options
const wsTransport = new RoochWebSocketTransport({
  url: getRoochNodeUrl('testnet'),
  reconnectDelay: 1000, // Delay between reconnection attempts (default: 1000ms)
  maxReconnectAttempts: 5, // Maximum number of reconnection attempts (default: 5)
  requestTimeout: 30000, // Request timeout (default: 30000ms)
  connectionReadyTimeout: 5000, // Connection ready timeout (default: 5000ms)
})

// Create client with WebSocket transport
const client = new RoochClient({
  transport: wsTransport,
})

// Use client as normal
await client.getBalances({
  owner: '',
})

// Clean up resources when done
client.destroy()

The WebSocket transport provides additional features:

  • Automatic reconnection on connection loss
  • Configurable timeouts and retry attempts
  • Connection state management
  • Resource cleanup

You can customize the WebSocket behavior through the following options:

  • url: WebSocket endpoint URL (required)
  • reconnectDelay: Delay between reconnection attempts in milliseconds
  • maxReconnectAttempts: Maximum number of reconnection attempts
  • requestTimeout: Timeout for individual requests
  • connectionReadyTimeout: Timeout for waiting for connection to be ready
  • protocols: WebSocket sub-protocols (optional)

Writing APIs

Session Account

import { RoochClient, Secp256k1Keypair, getRoochNodeUrl } from '@roochnetwork/rooch-sdk'

const client = new RoochClient({
  url: getRoochNodeUrl('testnet'),
})

const kp = Secp256k1Keypair.generate()

const session = await client.createSession({
  sessionArgs: {
    appName: 'your app name',
    appUrl: 'your app url',
    scopes: ['0x3::empty::empty_with_signer'],
  },
  signer: kp,
})

Move Call

import { RoochClient, getRoochNodeUrl, Transaction } from '@roochnetwork/rooch-sdk'

const client = new RoochClient({
  url: getRoochNodeUrl('testnet'),
})

const tx = new Transaction()
tx.callFunction({
  target: '0x3::empty::empty_with_signer',
  maxGas: 100000000, // 1RGas, DEFAULT_GAS 50000000 = 0.5RGas
})

const result = await client.signAndExecuteTransaction({
  transaction: tx,
  signer: session,
})

Reading APIs

Move view

import { RoochClient, getRoochNodeUrl } from '@roochnetwork/rooch-sdk'

const client = new RoochClient({
  url: getRoochNodeUrl('devnet'),
})

const result = await client.executeViewFunction(
  '0x49ee3cf17a017b331ab2b8a4d40ecc9706f328562f9db63cba625a9c106cdf35::counter::view',
)

Subscriptions

The SDK supports real-time subscriptions to events and transactions using WebSocket connections. Subscriptions allow your application to receive updates in real-time without polling.

Setting up a Subscription

To use subscriptions, you must initialize your RoochClient with a WebSocket transport:

import { RoochClient, RoochWebSocketTransport, getRoochNodeUrl } from '@roochnetwork/rooch-sdk'

// Create WebSocket transport
const wsTransport = new RoochWebSocketTransport({
  url: getRoochNodeUrl('testnet'),
})

// Create client with WebSocket transport
const client = new RoochClient({
  transport: wsTransport,
  subscriptionTransport: wsTransport, // Use the same transport for subscriptions
})

// Now you can use subscriptions

Subscribing to Events

// Subscribe to all events
const eventSubscription = await client.subscribe({
  type: 'event',
  onEvent: (event) => {
    console.log('Received event:', event.data)
  },
  onError: (error) => {
    console.error('Subscription error:', error)
  },
})

// Subscribe to events with a filter
const filteredEventSubscription = await client.subscribe({
  type: 'event',
  filter: {
    sender: '0x123...', // Filter events by sender
  },
  onEvent: (event) => {
    console.log('Received filtered event:', event.data)
  },
})

// Later, unsubscribe when no longer needed
client.unsubscribe(eventSubscription.id)

Subscribing to Transactions

// Subscribe to all transactions
const txSubscription = await client.subscribe({
  type: 'transaction',
  onEvent: (event) => {
    console.log('Received transaction:', event.data)
  },
  onError: (error) => {
    console.error('Subscription error:', error)
  },
})

// Subscribe to transactions with a filter
const filteredTxSubscription = await client.subscribe({
  type: 'transaction',
  filter: {
    sender: '0x123...', // Filter transactions by sender
  },
  onEvent: (event) => {
    console.log('Received filtered transaction:', event.data)
  },
})

// Later, unsubscribe when no longer needed
client.unsubscribe(txSubscription.id)

Subscription Events

The

onEvent

callback receives an object with:

type

: Either 'event' or 'transaction'

data

: The event or transaction data

Handling Connection Issues

The WebSocket transport automatically handles reconnection on connection loss. You can configure its behavior using the options described in the WebSocket Connection section above.

When reconnection happens, subscriptions are automatically re-established.

Cleaning Up

Always clean up resources when done:

// Unsubscribe from all subscriptions
client.unsubscribe(subscription1.id)
client.unsubscribe(subscription2.id)

// Destroy the client to free resources
client.destroy()

Building Locally

To get started you need to install pnpm, then run the following command:

# Install all dependencies
$ pnpm install
# Run the build for the TypeScript SDK
$ pnpm build

All pnpm commands are intended to be run in the root of the Rooch repo. You can also run them within the sdk/typescript directory, and remove change pnpm sdk to just pnpm when running commands.

Type Doc

For the latest docs for the main branch, run pnpm doc and open the doc/index.html in your browser.

Testing

To run tests

pnpm test

check compatibility

pnpm gen
pnpm test