Gateway interface for oracle communication

The Gateway class provides the connection between your application and Switchboard oracle operators. It handles:

  • Fetching signed price data from oracles
  • Managing oracle selection and consensus
  • Batch operations for multiple feeds
  • Network latency optimization

Gateways are geo-distributed endpoints that route requests to available oracle operators for optimal performance.

// Create gateway from URL
const gateway = new Gateway(program, 'https://gateway.switchboard.xyz');

// Fetch signatures for feeds
const response = await gateway.fetchSignatures({
feedConfigs: [{
jobs: [buildBinanceJob('BTCUSDT')],
maxVariance: 1.0,
minResponses: 3,
}],
numSignatures: 5,
});

Gateway

Constructors

  • Constructs a Gateway instance

    Parameters

    • program: Program

      The Anchor program instance

    • gatewayUrl: string

      The URL of the switchboard gateway

    • OptionaloracleKey: PublicKey

      Optional specific oracle key

    Returns Gateway

Properties

gatewayUrl: string

The URL of the switchboard gateway

oracleKey?: PublicKey

Optional specific oracle key

program: Program

The Anchor program instance

Methods

  • Fetches signatures from the gateway. REST API endpoint: /api/v1/gateway_attest_enclave

    Parameters

    • params: {
          oracle_ed25519_enclave_signer: string;
          oracle_pubkey: string;
          oracle_reward_wallet: string;
          oracle_secp256k1_enclave_signer: string;
          quote: string;
          recentHash: string;
          timestamp: number;
      }

    Returns Promise<AttestEnclaveResponse>

    A promise that resolves to the attestation response.

    if the request fails.

  • Fetches a quote from the gateway.

    REST API endpoint: /api/v1/gateway_fetch_quote

    Parameters

    • params: { blockhash: string; get_for_guardian: boolean; get_for_oracle: boolean }

    Returns Promise<FetchQuoteResponse[]>

    A promise that resolves to the quote response.

    if the request fails.

  • Fetches the randomness reveal from the gateway.

    Parameters

    • params:
          | {
              randomnessAccount: PublicKey;
              rpc?: string;
              slot: number;
              slothash: string;
          }
          | { minStalenessSeconds: number; randomnessId: string; timestamp: number }

      The parameters for the randomness reveal.

    Returns Promise<RandomnessRevealResponse>

    The randomness reveal response.

  • Fetches signatures from the gateway.

    REST API endpoint: /api/v1/fetch_signatures

    Parameters

    • params: {
          jobs: IOracleJob[];
          maxVariance?: number;
          minResponses?: number;
          numSignatures?: number;
          recentHash?: string;
          useTimestamp?: boolean;
      }

    Returns Promise<{ failures: string[]; responses: FeedEvalResponse[] }>

    A promise that resolves to the feed evaluation responses.

    if the request fails.

  • Fetches signatures from the gateway without pre-encoded jobs REST API endpoint: /api/v1/fetch_signatures_batch

    Parameters

    • params: {
          feedConfigs: FeedRequest[];
          numSignatures?: number;
          recentHash?: string;
          useTimestamp?: boolean;
      }

    Returns Promise<FetchSignaturesBatchResponse>

    A promise that resolves to the feed evaluation responses.

    if the request fails.

  • Fetches signatures from the gateway.

    REST API endpoint: /api/v1/fetch_signatures

    Parameters

    • params: {
          encodedJobs: string[];
          maxVariance: number;
          minResponses: number;
          numSignatures: number;
          recentHash?: string;
          useTimestamp?: boolean;
      }

    Returns Promise<{ failures: string[]; responses: FeedEvalResponse[] }>

    A promise that resolves to the feed evaluation responses.

    if the request fails.

  • Fetches signatures from the gateway. REST API endpoint: /api/v1/fetch_signatures_batch

    Parameters

    • params: {
          encodedConfigs: {
              encodedJobs: string[];
              maxVariance: number;
              minResponses: number;
          }[];
          numSignatures: number;
          recentHash?: string;
          useTimestamp?: boolean;
      }

    Returns Promise<FetchSignaturesBatchResponse>

    A promise that resolves to the feed evaluation responses.

    if the request fails.

  • Parameters

    • params: {
          encodedConfigs: {
              encodedJobs: string[];
              maxVariance: number;
              minResponses: number;
          }[];
          numSignatures: number;
          recentHash?: string;
          useTimestamp?: boolean;
      }

    Returns Promise<FetchSignaturesMultiResponse>