### Install Dependencies for Switchboard Core SDK Source: https://github.com/switchboard-xyz/switchboard/blob/main/README.md After cloning the repository, this command installs the necessary Node Package Manager (npm) dependencies using pnpm. Ensure you have Node.js and pnpm installed. ```bash cd core-sdk pnpm install ``` -------------------------------- ### Clone Switchboard Core SDK Repository Source: https://github.com/switchboard-xyz/switchboard/blob/main/README.md This command clones the Switchboard Core SDK repository and its submodules. It's the first step to getting started with the SDK. ```bash git clone --recurse-submodules https://github.com/switchboard-xyz/core-sdk.git cd core-sdk ``` -------------------------------- ### sb solana network start Source: https://github.com/switchboard-xyz/switchboard/blob/main/cli/README.md Starts a Switchboard Solana network from a JSON configuration file. This command allows for various network configurations, including specifying RPC URLs, cluster types, and commitment levels. ```APIDOC ## POST /solana/network/start ### Description Starts a Switchboard Solana network from a JSON file. Allows for configuration of RPC URLs, cluster types, and commitment levels. ### Method POST ### Endpoint /solana/network/start ### Parameters #### Query Parameters - **silent** (boolean) - Optional - Suppress docker logging. - **verbose** (boolean) - Optional - Log everything. - **mainnetBeta** (boolean) - Optional - Use mainnet-beta Solana cluster. - **cluster** (string) - Optional - The Solana cluster to connect to (devnet, mainnet-beta, mainnet, localnet). - **rpcUrl** (string) - Optional - Alternate RPC URL. - **programId** (string) - Optional - Alternative Switchboard program ID. - **attestationProgramId** (string) - Optional - Alternative Switchboard Attestation program ID. - **commitment** (string) - Optional - Transaction commitment level (confirmed, finalized, processed). - **keypair** (string) - Optional - Keypair that will pay for on-chain transactions. - **ledgerPath** (string) - Optional - HID path to the ledger. - **ledger** (boolean) - Optional - Enable ledger support. - **json** (boolean) - Optional - Format output as JSON. - **configFile** (string) - Optional - Path to the configuration file. - **schemaFile** (string) - Optional - Path to the schema file. - **nodeImage** (string) - Optional - Public key of the oracle to start-up. - **arm** (boolean) - Optional - Use a docker image for linux/arm64 (for Apple Silicon). - **timeout** (number) - Optional - Number of seconds before ending the docker process. - **mainnetRpcUrl** (string) - Optional - Solana mainnet RPC URL for the oracle task runner. ### Request Example ```json { "silent": true, "cluster": "devnet", "rpcUrl": "https://api.devnet.solana.com" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message of network start. #### Response Example ```json { "message": "Switchboard network started successfully." } ``` ``` -------------------------------- ### Install @switchboard-xyz/common Package Source: https://github.com/switchboard-xyz/switchboard/blob/main/javascript/common/README.md Installs the @switchboard-xyz/common package using npm. This is the first step to using the package's functionalities in your project. ```bash npm i --save @switchboard-xyz/common ``` -------------------------------- ### Fetch Pyth Oracle Price (JSON) Source: https://github.com/switchboard-xyz/switchboard/blob/main/website/protos/examples/dex.mdx Configure Switchboard to fetch price data from the Pyth oracle network. This example shows how to get the SOL/USD price and sets an allowed confidence interval. ```json { "name": "Pyth SOL/USD", "tasks": [ { "oracleTask": { "pythAddress": "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG", "pythAllowedConfidenceInterval": 0.002 } } ] } ``` -------------------------------- ### TypeScript Multi-Source Price Feed Implementation Source: https://context7.com/switchboard-xyz/switchboard/llms.txt An end-to-end TypeScript example demonstrating the creation of a production-ready multi-source price feed using the Switchboard SDK. It defines and simulates price jobs from Binance, Coinbase, and Kraken, and includes pseudo-code for deploying an aggregator. ```typescript import { OracleJob, serializeOracleJob, simulateOracleJobs, networks } from "@switchboard-xyz/common"; import { DockerOracle } from "@switchboard-xyz/oracle"; // Define multiple price sources const binanceJob = { tasks: [ { httpTask: { url: "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT" } }, { jsonParseTask: { path: "$.price" } } ] }; const coinbaseJob = { tasks: [ { httpTask: { url: "https://api.coinbase.com/v2/prices/BTC-USD/spot", headers: [ { key: "Accept", value: "application/json" } ] } }, { jsonParseTask: { path: "$.data.amount" } } ] }; const krakenJob = { tasks: [ { httpTask: { url: "https://api.kraken.com/0/public/Ticker?pair=XBTUSD" } }, { jsonParseTask: { path: "$.result.XXBTZUSD.c[0]" } } ] }; // Test all jobs async function testJobs() { const jobs = [binanceJob, coinbaseJob, krakenJob].map(j => serializeOracleJob(j) ); console.log("Testing price feeds..."); const result = await simulateOracleJobs(jobs, "mainnet-beta"); if ("error" in result) { throw new Error(`Simulation failed: ${result.error}`); } console.log("Individual results:", result.results.map(r => r.toString())); console.log("Aggregated result:", result.result.toString()); return result; } // Deploy aggregator (pseudo-code for CLI integration) async function deployAggregator() { // Save jobs to files const fs = require("fs"); fs.writeFileSync("btc-binance.json", JSON.stringify(binanceJob, null, 2)); fs.writeFileSync("btc-coinbase.json", JSON.stringify(coinbaseJob, null, 2)); fs.writeFileSync("btc-kraken.json", JSON.stringify(krakenJob, null, 2)); console.log("Job files created. Deploy with:"); console.log(` sb solana:aggregator:create $QUEUE_KEY \ --name "BTC/USD Multi-Source" \ --updateInterval 30 \ --minOracles 3 \ --minJobs 2 \ --job btc-binance.json \ --job btc-coinbase.json \ --job btc-kraken.json \ --enable `); } // Main execution (async () => { try { // Test the jobs const testResult = await testJobs(); console.log("All jobs passed simulation"); // Deploy aggregator await deployAggregator(); console.log("Setup complete!"); } catch (error) { console.error("Error:", error.message); process.exit(1); } })(); ``` -------------------------------- ### Initialize and Run Docker Oracle Source: https://github.com/switchboard-xyz/switchboard/blob/main/javascript/oracle/README.md Illustrates the initialization and execution of a Switchboard Oracle using Docker. Similar to the NodeJS version, it configures the oracle with release channel, network, RPC URL, oracle key, and secret path, then starts it and waits for it to become operational. Includes error handling and stopping procedures. ```typescript import { DockerOracle } from "@switchboard-xyz/oracle"; const oracle = await DockerOracle.fromReleaseChannel({ releaseChannel: "testnet", chain: "solana", network: "localnet", rpcUrl: "http://0.0.0.0:8899", oracleKey: "FKFPBD5WUUL5bSNwBH3AKY58KuY8nz2zkMCYR271CcVA", secretPath: "~/.config/solana/id.json", }); try { await oracle.startAndAwait(); console.log("oracle ready"); await sleep(10000); } catch (error) { console.error(error); } oracle.stop(); ``` -------------------------------- ### Initialize and Run NodeJS Oracle Source: https://github.com/switchboard-xyz/switchboard/blob/main/javascript/oracle/README.md Demonstrates how to initialize and run a Switchboard Oracle within a NodeJS environment. It configures the oracle with specific release channel, network, RPC URL, oracle key, and secret path, then starts it and awaits its readiness. Includes basic error handling and cleanup. ```typescript import { NodeOracle } from "@switchboard-xyz/oracle"; const oracle = await NodeOracle.fromReleaseChannel({ releaseChannel: "testnet", chain: "solana", network: "localnet", rpcUrl: "http://0.0.0.0:8899", oracleKey: "FKFPBD5WUUL5bSNwBH3AKY58KuY8nz2zkMCYR271CcVA", secretPath: "~/.config/solana/id.json", }); try { await oracle.startAndAwait(); console.log("oracle ready"); await sleep(10000); } catch (error) { console.error(error); } oracle.stop(); ``` -------------------------------- ### Install Switchboard CLI Source: https://github.com/switchboard-xyz/switchboard/blob/main/cli/README.md Installs or updates the Switchboard CLI globally using npm. This command ensures you have the latest version of the CLI available in your system's PATH for easy access. ```bash npm install -g @switchboard-xyz/cli sb update stable ``` -------------------------------- ### Install Switchboard Oracle Package Source: https://github.com/switchboard-xyz/switchboard/blob/main/javascript/oracle/README.md Installs the @switchboard-xyz/oracle package as a development dependency using npm. This command is essential for projects that will utilize the Switchboard V2 oracle functionalities. ```bash npm i --save-dev @switchboard-xyz/oracle ``` -------------------------------- ### Fetch JupiterSwap Swap Price (JSON) Source: https://github.com/switchboard-xyz/switchboard/blob/main/website/protos/examples/dex.mdx Configure Switchboard to find the best swap price between two tokens on JupiterSwap. This example shows how to swap JSOL for USDC. ```json { "name": "JupiterSwap JSOL to USDC", "tasks": [ { "jupiterSwapTask": { "inTokenAddress": "7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn", "outTokenAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" } } ] } ``` -------------------------------- ### Fetch Jet Lending Rate (JSON) Source: https://github.com/switchboard-xyz/switchboard/blob/main/website/protos/examples/dex.mdx Obtain the lending rate for a specified asset from the Jet lending protocol using Switchboard. This example retrieves the lending rate for BTC. ```json { "name": "JET BTC Lend Rate", "tasks": [ { "lendingRateTask": { "protocol": "jet", "assetMint": "9n4nbM75f5Ui33ZbPYXn59EwSgE8CGsHtAeTH5YFeJ9E", "field": 0 } } ] } ``` -------------------------------- ### Create Solana Function Account CLI Command Source: https://github.com/switchboard-xyz/switchboard/blob/main/cli/README.md This command-line interface (CLI) command is used to create a new function account on the Solana blockchain. It requires the public key of the attestation queue and various optional flags to configure the function's container, networking, and permissions. Ensure you have the Solana CLI and Switchboard SDK installed. ```bash sb solana function create QUEUEKEY --container [-h] [-v] [-s] [--mainnetBeta | --cluster devnet|mainnet-beta|mainnet|localnet] [-u ] [--programId ] [--attestationProgramId ] [--commitment confirmed|finalized|processed] [-k ] [--ledgerPath --ledger] [--json] [-n ] [--metadata ] [-a ] [--fundAmount ] [--containerRegistry dockerhub|ipfs] [--version ] [--mrEnclave ] [--requestsDisabled] [--requestsFee ] [--requestsRequireAuthorization] [--routinesDisabled] [--routinesFee ] [--routinesRequireAuthorization] ARGUMENTS: QUEUEKEY public key of the attestation queue account FLAGS: -a, --authority= keypair or public key to delegate authority to for managing the function account -h, --help Show CLI help. -k, --keypair= keypair that will pay for onchain transactions. defaults to new account authority if no alternate authority provided -n, --name= name of the function for easier identification -s, --silent suppress cli prompts -u, --rpcUrl= alternate RPC url -v, --verbose log everything --attestationProgramId= alternative Switchboard Attestation program ID to interact with --cluster=