Switchboard On-Demand Feeds are designed for maximum, speed, security, and simplicity. This quick-start guide will demonstrate how to use an existing Switchboard On-Demand Feed.
For a quick-start guide on creating new feeds via Typescript, see: Quickstart: Build and Use.
Start with Designing a feed for a more in-depth walkthrough on the process of creating and deploying with Switchboard.
Step 1: Getting a Solana Feed Public Key
Browse our awesome Explorer for a feed you like and save the feeds public key!
You can also create a feed in our On-Demand Builder, which is a tool for building and deploying feeds directly from the a user interface. You can use it to pull data from almost anywhere. See the Designing a Feed section for more on configuring oracle jobs.
Now using this SDK and the public key of the feed:
Initialize the feed account object,
Fetch an update instruction for the latest feed update!
Submit it to the chain along with your programs instruction!
// Replace with your feed pubkeyconstfeed=newPublicKey("HvMrsyD5p1Jg7PTCkLq3bkb5Hs1r3ToYex3ixZ1Mq47A");constfeedAccount=newsb.PullFeed(program, feed);constdemoPath="target/deploy/sb_on_demand_solana-keypair.json";constdemo=awaitmyAnchorProgram(program.provider, demoPath);// Get the update instruction for switchboard and lookup tables to make the instruction lighterconst [pullIx,responses,success,luts] =awaitfeedAccount.fetchUpdateIx();// Instruction to example program using the switchboard feedconstmyIx=awaitdemo.methods.test().accounts({ feed }).instruction();// Create the transactionconsttx=awaitsb.asV0Tx({ connection, ixs: [pullIx, myIx], signers: [keypair], computeUnitPrice:200_000, computeUnitLimitMultiple:1.3, lookupTables: luts,});// simulate the transactionconstsimulateResult=awaitqueue.program.provider.connection.simulateTransaction(tx, { commitment:"processed", });console.log(simulateResult);// Send the transaction via rpc constsig=awaitconnection.sendTransaction(tx, { commitment:"processed" });