Switchboard Surge Skill
Purpose
Use Switchboard Surge for low-latency streaming:
Subscribe to signed updates over WebSocket
Monitor latency/health and implement reconnection
Convert signed updates for on-chain settlement (chain-specific)
Dependencies
Use exact pins from the SDK Version Matrix.
@switchboard-xyz/[email protected]@switchboard-xyz/[email protected](EVM conversion path)@switchboard-xyz/[email protected](Sui conversion path)
Preconditions
OperatorPolicyexists.If creating/modifying a paid subscription, explicit approval is required.
Inputs to Collect
subscription wallet/network (Solana)
symbol/feed list
target usage: bot-only vs on-chain settlement vs UI display
validation thresholds (max staleness, deviation checks) if safety-critical
Minimal Example
Playbook
1) Subscribe to signed updates (TypeScript skeleton)
Subscription
Surge subscriptions are managed on Solana via the Surge program (orac1eFjzWL5R3RbbdMV68K9H6TaCVVcL6LjvQQWAbz). To subscribe programmatically:
Choose a tier (Plug/Pro/Enterprise). Tiers are on-chain PDAs.
Acquire SWTCH tokens (payments are in SWTCH only).
Fetch a fresh SWTCH/USDT oracle quote and include it in the same transaction.
Call
subscription_initwithtier_idandepoch_amount. The program prices the subscription in SWTCH using the live quote and creates your subscription PDA.
Key notes:
If the keypair has no active subscription,
connectAndSubscribefails.Tiers and limits are enforced on-chain (max feeds, connections, min delay).
For UI-free flows, derive PDAs (
STATE,TIER,SUBSCRIPTION) and pass required accounts.
Minimal sketch (quote + subscription_init in one tx):
Connection Flow (Gateway Auth)
If you are not using the SDK's surge.connectAndSubscribe(...), implement this auth flow directly:
Discover a gateway
GET https://crossbar.switchboard.xyz/gateways?network=mainnet(ordevnet)
Create signature headers
Build message hash:
SHA256("{blockhash}:{timestamp}")Sign with Ed25519 (your Solana keypair)
Send headers:
X-Switchboard-SignatureX-Switchboard-PubkeyX-Switchboard-BlockhashX-Switchboard-Timestamp
Request a stream session
POST {gateway}/gateway/api/v1/request_streamInclude all
X-Switchboard-*headersRead
session_token+oracle_ws_urlfrom response
Open authenticated WebSocket
Connect to
oracle_ws_urlwith:Authorization: Bearer {pubkey}:{session_token}the same
X-Switchboard-*headers
Subscribe + keepalive
Send a
Subscribemessage (feeds + signature fields)When gateway sends
SignedPing, reply withSignedPongusing a fresh blockhash + timestamp + signature
Minimal message shape:
2) Convert for on-chain settlement
Solana: convert to quote/update instructions and include before consumer ix in the same tx.
EVM: convert to EVM-compatible bytes and submit via
updateFeeds.
3) Reliability
heartbeat monitoring
exponential backoff reconnect
last-seen tracking and gap detection
metrics logging
References
https://docs.switchboard.xyz/docs-by-chain/solana-svm/surge
https://docs.switchboard.xyz/ai-agents-llms/surge-subscription-guide
https://docs.switchboard.xyz/tooling/crossbar/gateway-protocol
https://docs.switchboard.xyz/docs-by-chain/evm/surge
https://docs.switchboard.xyz/docs-by-chain/sui/surge
Last updated