Developers: Quickstart!

Using a Switchboard-On-Demand Feed is design for maximum, speed, secuirty, and simplicity

With our new On-Demand service, we at Switchboard have made it super easy to integrate and run a feed!

First things first! Browse our awesome Explorer for a feed you like and save the feeds public key!

The, get started by installing our Javascript/Typescript SDK via:

# https://switchboard-docs.web.app/
npm i @switchboard-xyz/on-demand

Now using this SDK and the public key of the feed:

  1. Initialise the feed account,

  2. Fetch an update instruction for the latest feed update!

  3. Submit it to the chain along with your programs instruction!

const feed = new PublicKey("HvMrsyD5p1Jg7PTCkLq3bkb5Hs1r3ToYex3ixZ1Mq47A");
const feedAccount = new sb.PullFeed(program, feed);
const demoPath = "target/deploy/sb_on_demand_solana-keypair.json";
const demo = await myAnchorProgram(program.provider, demoPath);
const myIx = await demo.methods.test().accounts({ feed }).instruction();

const [pullIx, responses, success] = await feedAccount.fetchUpdateIx({ numSignatures: 3 });

const lutOwners = [...responses.map((x) => x.oracle), feedAccount];
const tx = await sb.asV0Tx({
      connection,
      ixs: [pullIx, myIx],
      signers: [keypair],
      computeUnitPrice: 200_000,
      computeUnitLimitMultiple: 1.3,
      lookupTables: await sb.loadLookupTables(lutOwners),
    });
const sig = await connection.sendTransaction(tx, { commitment: "processed" });

Now how easy is that!

Check out this repo for a full example! https://github.com/switchboard-xyz/sb-on-demand-examples/blob/main/sb-on-demand-feeds/scripts/runFeed.ts Need more in-depth info? Next Page!

Last updated