Constructs a Gateway instance
The Anchor program instance
The URL of the switchboard gateway
Optional
oracleKey: PublicKeyOptional specific oracle key
Initializes a Surge instance
The parameters for the surge instance
The API key for authentication
Optional
verbose?: booleanWhether to enable verbose logging
A new instance of dSurge
Fetches signatures from the gateway.
REST API endpoint: /api/v1/fetch_signatures
A promise that resolves to the feed evaluation responses.
Fetches signatures from the gateway. REST API endpoint: /api/v1/gateway_attest_enclave
A promise that resolves to the attestation response.
Fetches an attestation quote from the gateway.
REST API endpoint: /api/v1/gateway_fetch_quote
A promise that resolves to the quote response.
Fetches signatures from the gateway.
REST API endpoint: /api/v1/fetch_signatures
A promise that resolves to the feed evaluation responses.
Fetches signatures from multiple feeds
A promise that resolves to the feed evaluation responses.
Fetches signatures from the gateway without pre-encoded jobs REST API endpoint: /api/v1/fetch_signatures_batch
A promise that resolves to the feed evaluation responses.
Fetches signatures from the gateway. REST API endpoint: /api/v1/fetch_signatures_batch
A promise that resolves to the feed evaluation responses.
Fetches signatures using consensus mechanism REST API endpoint: /api/v1/fetch_signatures_consensus
A promise that resolves to the consensus response.
Fetches oracle quote data from the gateway
This method retrieves signed price quotes from oracle operators through the gateway interface. It's the primary method for fetching oracle data using the modern quote terminology.
The returned response contains:
oracle_responses
: Array of signed oracle datarecent_hash
: Recent Solana block hash for replay protectionslot
: Recent slot number for temporal validationCrossbar client for data routing and feed resolution
Array of feed hashes to fetch (hex strings, max 16)
Number of oracle signatures required (default: 1, max based on queue config)
Optional
variableOverrides: Record<string, string>Oracle quote response with signatures
import { CrossbarClient } from '@switchboard-xyz/common';
// Initialize crossbar client
const crossbar = CrossbarClient.default();
// Single feed quote
const btcQuote = await gateway.fetchQuote(
crossbar,
['0xef0d8b6fcd0104e3e75096912fc8e1e432893da4f18faedaacca7e5875da620f'], // BTC/USD
1 // Single signature for fast updates
);
// Multi-feed quote for DeFi protocol
const defiAssets = [
'0xef0d8b6fcd0104e3e75096912fc8e1e432893da4f18faedaacca7e5875da620f', // BTC/USD
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', // ETH/USD
'0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890', // SOL/USD
'0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba' // USDC/USD
];
const portfolioQuote = await gateway.fetchQuote(
crossbar,
defiAssets,
5 // Higher consensus for financial operations
);
// Access oracle responses
console.log('Oracle responses:', portfolioQuote.oracle_responses.length);
console.log('Recent slot:', portfolioQuote.slot);
// Process individual feed responses
portfolioQuote.oracle_responses.forEach((oracle, index) => {
oracle.feed_responses.forEach((feed, feedIndex) => {
console.log(`Oracle ${index}, Feed ${feedIndex}:`, {
feedHash: feed.feed_hash,
value: feed.success_value,
confidence: feed.min_oracle_samples
});
});
});
Use fetchQuote instead. The bundle terminology has been replaced with quote terminology.
Fetches oracle bundle data from the gateway
Sends a request to the gateway bridge enclave.
REST API endpoint: /api/v1/gateway_bridge_enclave
A promise that resolves to the response.
Fetches the randomness reveal from the gateway.
The parameters for the randomness reveal.
The randomness reveal response.
Gateway interface for oracle communication
The Gateway class provides the connection between your application and Switchboard oracle operators. It handles:
Gateways are geo-distributed endpoints that route requests to available oracle operators for optimal performance.
Variable Overrides
Variable overrides allow you to dynamically customize oracle task execution by providing key-value pairs that replace variables within oracle jobs. This is particularly useful for:
Usage Examples
Variable Syntax in Jobs
Variables in oracle jobs use the
${VARIABLE_NAME}
syntax:Best Practices
Gateway