This tutorial shows you how to stream real-time price data via WebSocket using Switchboard Surge and submit updates to the Sui blockchain. This approach is ideal for applications requiring sub-second price updates.
What You'll Build
A TypeScript application that:
Connects to Switchboard Surge for real-time price streaming via WebSocket
Receives signed price updates with sub-second latency
The emitSurgeQuote() function handles converting the Surge response into a valid Sui transaction.
Mainnet vs Testnet
The mainnet and testnet examples are nearly identical with these differences:
Setting
Mainnet
Testnet
RPC URL
https://fullnode.mainnet.sui.io:443
https://fullnode.testnet.sui.io:443
Oracle Mapping
/oracles/sui
/oracles/sui/testnet
Testnet Configuration
Running the Examples
1. Clone the Repository
2. Install Dependencies
3. Ensure Active Subscription
Your Solana keypair (default ~/.config/solana/id.json or SOLANA_KEYPAIR_PATH) must have an active Surge subscription. The Sui keypair only signs Sui transactions. Subscribe at explorer.switchboardlabs.xyz/subscriptions.
4. Run the Examples
Expected Output
Adding to Your Project
Dependencies
Minimal Integration
This example assumes you already loaded a solanaKeypair (with an active Surge subscription) and a suiKeypair (for signing Sui transactions).
Multiple Feeds
Error Handling
Performance Considerations
Transaction Queue
The example uses a queue because:
Sui transactions are sequential per sender
Surge updates arrive faster than transactions complete
Queuing prevents transaction conflicts
Latency Optimization
Keep your Sui node geographically close
Use dedicated RPC endpoints for production
Consider batching updates if latency isn't critical
Oracle Mapping Cache
The oracle mapping is cached for 10 minutes to avoid repeated API calls. Adjust ORACLE_CACHE_TTL based on your needs.
Troubleshooting
"Keypair not loaded"
Ensure you have a valid Sui keypair in ~/.sui/sui_config/sui.keystore
Run sui client new-address ed25519 to create one
Ensure you have a valid Solana keypair at ~/.config/solana/id.json or SOLANA_KEYPAIR_PATH
Run solana-keygen new to create one
"Subscription not found" or connection rejected
Ensure your Solana keypair has an active Surge subscription