跳到正文
Skillpedia
API 与服务器(后端)7.0k · #13683

switchboard

它能做什么

这项技能指导集成 Switchboard,这是 Solana 上一个无需许可的预言机协议。它适合需要价格数据源、可验证随机数或自定义数据用于其程序的开发者。

适用场景

  • ✓当你的 Solana 程序需要来自无需审批即可部署的预言机的价格数据时。
  • ✓当你需要为游戏或抽奖功能提供可验证随机数的时候。
  • ✓当你希望通过 Surge 服务获取低延迟数据流的时候。

技能链接

https://github.com/internet-court/internet-court-skill/blob/main/vendored/sendaifun/switchboard/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/internet-court/internet-court-skill/blob/main/vendored/sendaifun/switchboard/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我为我的 Solana 程序添加 Switchboard 价格数据源,并读取最新价格。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会设置 Switchboard SDK,在按需报价、价格数据源和数据流之间选择,并编写读取数据的代码。它会根据你的项目使用 Rust 或 TypeScript 集成。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Switchboard Oracle Protocol - Complete Integration Guide

The definitive guide for integrating Switchboard - the fastest, most customizable, and only permissionless oracle protocol on Solana.

What is Switchboard?

Switchboard is a permissionless oracle protocol enabling developers to bring custom data on-chain with industry-leading performance:

  • Price Feeds - Real-time asset pricing with pull-based efficiency
  • Oracle Quotes - Sub-second latency without on-chain storage (90% cost reduction)
  • Surge - WebSocket streaming with sub-100ms latency
  • VRF Randomness - Cryptographically secure verifiable random functions
  • Prediction Markets - Market-based forecasting data

Key Statistics

  • Secures $1B+ in on-chain volume
  • Used by Kamino, Jito, MarginFi, Drift Protocol
  • 2-5ms latency with Surge pricing
  • 90% cost reduction vs traditional oracles

Core Principles

Principle Description
Speed 2-5ms with Surge, 400ms standard - industry-leading for DeFi
Cost Efficiency Pull-based feeds eliminate constant streaming costs
Permissionless Deploy feeds instantly without approvals
Security TEE (Trusted Execution Environments) prevent data manipulation

Integration Approaches

1. Oracle Quotes (Recommended)

Direct oracle-to-program data flow without on-chain storage:

  • Sub-second latency
  • 90% cost reduction
  • No write locks (parallel reads)
  • Stateless design

2. Traditional Feeds

Classic pull-based feed updates:

  • Feed account maintenance
  • Cranking operations
  • Good for simple use cases

3. Surge (Real-Time)

WebSocket streaming for high-frequency applications:

  • Sub-100ms latency
  • Persistent connections
  • Ideal for trading interfaces

Program IDs

Program Mainnet Devnet
Oracle Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f Aio4gaXjXzJNVLtzwtNVmSqGKpANtXhybbkhtAC94ji2
Quote Program orac1eFjzWL5R3RbbdMV68K9H6TaCVVcL6LjvQQWAbz -

Default Queues

Network Queue Address
Mainnet A43DyUGA7s8eXPxqEjJY6EBu1KKbNgfxF8h17VAHn13w
Devnet EYiAmGSdsQTuCw413V5BzaruWuCCSDgTPtBGvLkXHbe7

Quick Start

Installation

# TypeScript SDK
npm install @switchboard-xyz/on-demand @switchboard-xyz/common

# Rust (Cargo.toml)
# switchboard-on-demand = "0.8.0"

Basic Setup

import { web3, AnchorProvider, Program } from "@coral-xyz/anchor";
import {
  PullFeed,
  CrossbarClient,
  ON_DEMAND_MAINNET_PID,
  ON_DEMAND_DEVNET_PID
} from "@switchboard-xyz/on-demand";

// Setup connection and provider
const connection = new web3.Connection("https://api.mainnet-beta.solana.com");
const wallet = useWallet(); // or Keypair
const provider = new AnchorProvider(connection, wallet);

// Load Switchboard program
const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);

// Initialize Crossbar client for oracle communication
const crossbar = new CrossbarClient("https://crossbar.switchboard.xyz");

Price Feeds

Fetch and Update Feed

import { PullFeed, asV0Tx } from "@switchboard-xyz/on-demand";

// Create feed account reference
const feedPubkey = new web3.PublicKey("YOUR_FEED_PUBKEY");
const feedAccount = new PullFeed(sbProgram, feedPubkey);

// Fetch update instruction with oracle signatures
const { pullIx, responses, numSuccess, luts } = await feedAccount.fetchUpdateIx({
  crossbarClient: crossbar,
  chain: "solana",
  network: "mainnet", // or "devnet"
});

// Build and send transaction
const tx = await asV0Tx({
  connection,
  ixs: [pullIx],
  signers: [payer],
  computeUnitPrice: 200_000,
  computeUnitLimitMultiple: 1.3,
  lookupTables: luts,
});

const signature = await connection.sendTransaction(tx);
console.log("Feed updated:", signature);

Read Feed Value

// Get current feed value
const feedData = await feedAccount.loadData();
const value = feedData.value.toNumber();
const lastUpdated = feedData.lastUpdatedSlot;

console.log(`Price: ${value}, Last Updated: ${lastUpdated}`);

Oracle Quotes (Recommended)

Oracle Quotes provide the most efficient way to consume oracle data:

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

// Feed hashes (64-char hex strings)
const feedHashes = [
  "0x...", // SOL/USD
  "0x...", // BTC/USD
];

// Derive canonical quote account
const queueKey = new web3.PublicK
常见问题

Switchboard 无需许可吗?

是的。该技能说明,你无需任何人批准即可部署数据源。

什么是 VRF 随机数?

该技能将其描述为一种可验证的随机函数,能够提供安全的随机值。

它使用安全硬件吗?

该技能说明,可信执行环境有助于防止数据被篡改。

详情

作者的原始描述

Complete Switchboard Oracle Protocol SDK for Solana - the permissionless oracle solution for price feeds, on-demand data, VRF randomness, and real-time streaming via Surge. Covers TypeScript SDK, Rust integration, Oracle Quotes, and all Switchboard tools.

repo: internet-court/internet-court-skill

热度

GitHub 星标
7.0k
排名
#13683
许可证
—
更新时间
2026/10/26

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能