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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@switchboard-xyz/on-demand

v3.7.3

Published

A Typescript client to interact with Switchboard On-Demand.

Readme

Switchboard Logo

Switchboard

Switchboard On-Demand (typedoc: https://switchboard-docs.web.app)

See the full documentation at Switchboard On-Demand Documentation

Switchboard On-Demand is designed to support high-fidelity financial systems. It allows users to specify how data from both on-chain and off-chain sources is ingested and transformed.

Unlike many pull-based blockchain oracles that manage data consensus on their own Layer 1 (L1) and then propagate it to users—giving oracle operators an advantage—Switchboard Oracles operate inside confidential runtimes. This setup ensures that oracles cannot observe the data they are collecting or the operations they perform, giving the end user a 'first-look' advantage when data is propagated.

Switchboard On-Demand is ideal for blockchain-based financial applications and services, offering a solution that is cost-effective, trustless, and user-friendly.

Key Features:

  • User-Created Oracles: In Switchboard, users have the flexibility to build their own oracles according to their specific needs.
  • Confidential Runtimes: Oracle operations are performed in a way that even the oracles themselves cannot observe, ensuring data integrity and user advantage.
  • High-Fidelity Financial Applications: Designed with financial applications in mind, Switchboard ensures high accuracy and reliability for transactions and data handling.

Browser Compatibility

This library is compatible with both Node.js and browser environments. However, some utility functions require Node.js file system access:

Node.js-Only Functions

  • AnchorUtils.initKeypairFromFile() - Use web3.Keypair.fromSecretKey() directly in browsers
  • AnchorUtils.initWalletFromFile() - Use browser wallet adapters (e.g., Phantom, Solflare) instead
  • AnchorUtils.loadEnv() - Use loadProgramFromConnection() with your own connection/wallet

Browser Usage Example

import * as sb from '@switchboard-xyz/on-demand';
import { Connection, clusterApiUrl } from '@solana/web3.js';

// Use browser wallet adapter instead of file-based keypair
const connection = new Connection(clusterApiUrl('mainnet-beta'));
const program = await sb.AnchorUtils.loadProgramFromConnection(
  connection,
  walletAdapter // From @solana/wallet-adapter-react or similar
);

// Rest of your code works identically in browser and Node.js
const [pullIx] = await feedAccount.fetchUpdateIx({ numSignatures: 3 });

Getting Started

To start building your own on-demand oracle with Switchboard, you can refer to the oracle specification in our documentation.

Example Code Snippet:

const [pullIx] = await feedAccount.fetchUpdateIx({ numSignatures: 3 });
const tx = await sb.asV0Tx({
    connection,
    ixs: [pullIx],
    signers: [payer],
    computeUnitPrice: 200_000,
    computeUnitLimitMultiple: 1.3,
});
await program.provider.connection.sendTransaction(tx, {
    // preflightCommitment is REQUIRED to be processed or disabled
    preflightCommitment: "processed",
});

SwitchboardSurge - Real-time Price Streaming

The SwitchboardSurge class provides real-time price streaming capabilities through WebSocket connections to Switchboard gateways.

Quick Start

import { SwitchboardSurge } from '@switchboard-xyz/on-demand';

// Initialize and subscribe to price feeds
const surge = new SwitchboardSurge({
  apiKey: 'your-api-key',
  gatewayUrl: 'http://localhost:8082', // Your gateway URL
});

// Listen for price updates
surge.on('data', (update) => {
  console.log('Price update:', update.processed.values);
});

// Subscribe to feeds (validation happens automatically)
await surge.subscribe([
  { symbol: 'BTCUSDT', source: 'BINANCE' },
  { symbol: 'ETHUSDT', source: 'BINANCE' },
]);

Event Handling

surge.on('connected', () => {
  console.log('Connected to Switchboard Surge');
});

surge.on('data', (response) => {
  // response.processed: Ready for Solana transactions
  console.log('Feed values:', response.processed.values);
  console.log('Feed hashes:', response.processed.feedHashes);
});

surge.on('error', (error) => {
  console.error('Streaming error:', error.message);
});

surge.on('disconnected', (code, reason) => {
  console.log('Disconnected:', code, reason);
});

Configuration

const surge = new SwitchboardSurge({
  apiKey: 'your-api-key',
  gatewayUrl: 'http://localhost:8082',  // Your gateway URL
  autoReconnect: true,                  // Auto-reconnect on disconnect
  maxReconnectAttempts: 5,              // Max reconnection attempts
  reconnectDelay: 1000,                 // Delay between reconnects (ms)
});

Oracle Quote Functionality

The OracleQuote class provides utilities for working with oracle quote accounts and verified oracle data.

Deriving Oracle Quote Accounts

import { OracleQuote } from '@switchboard-xyz/on-demand';

// Derive the canonical oracle quote account address from feed hashes
const feedHashes = [
  'your-feed-hash-1',
  'your-feed-hash-2'
];

const [oracleAccount, bump] = OracleQuote.getCanonicalPubkey(
  queueKey,   // Queue public key for canonical derivation (required)
  feedHashes  // Uses default program ID
);
console.log('Oracle Quote Account:', oracleAccount.toString());

// Or with a custom program ID:
const [customOracleAccount, customBump] = OracleQuote.getCanonicalPubkey(
  queueKey,
  feedHashes,
  customProgramId
);

The OracleQuote.getCanonicalPubkey() method:

  • Takes a queue public key as the first parameter (required)
  • Takes an array of feed hashes as the second parameter (32-byte hex strings or Buffers)
  • Optionally takes a program ID as the third parameter
  • Returns the program-derived address for the oracle quote account
  • Uses the default quote program ID orac1eFjzWL5R3RbbdMV68K9H6TaCVVcL6LjvQQWAbz if no program ID is provided
  • Matches the Rust implementation for consistent address derivation (queue key + feed hashes as seeds)

Feed Hash Format

Feed hashes must be provided as:

  • Hex strings: 64-character hex strings (with or without '0x' prefix)
  • Buffers: 32-byte Buffer objects
// Valid formats
const feedHashes = [
  '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
  '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
  Buffer.from('1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', 'hex')
];