Starknet

Active Deployments

The Switchboard On-Demand service is currently deployed on the following networks:

Check out the example contract to see how to create a price feed using Switchboard On-Demand.

Typescript-SDK Installation

To use Switchboard On-Demand, add the following dependencies to your project:

npm install @switchboard-xyz/starknet-sdk --save

Creating an Aggregator and Sending Transactions

Building a feed in Switchboard can be done using the Typescript SDK, or it can be done with the Switchboard Web App. Visit our docs for more on designing and creating feeds.

Building Feeds

import {
  SwitchboardClient,
  Aggregator,
  STARKNET_TESTNET_QUEUE,
  STARKNET_MAINNET_QUEUE,
} from "@switchboard-xyz/starknet-sdk";
import { Account, RpcProvider } from 'starknet';

// initialize starknet provider
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:5050/rpc' });
// initialize existing starknet account
const privateKey = '0x71d7bb07b9a64f6f78ac4c816aff4da9';
const accountAddress = '0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691';

const walletAccount = new Account(provider, accountAddress, privateKey);

const feedHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"; // replace with your feed hash

export async function createFeed() {
  // .. initialize wallet or starknet account ..
  const client = new SwitchboardClient(walletAccount);

  const params = {
    authority: walletAccount.address,
    name: "EXAMPLE/USD",
    queueId: STARKNET_TESTNET_QUEUE, // or STARKNET_MAINNET_QUEUE
    toleratedDelta: 100,
    maxStaleness: 100,
    feedHash,
    maxVariance: 5e9,
    minResponses: 1,
    minSamples: 1, // required to be 1 for Starknet
  };

  const aggregator = await Aggregator.init(client, params);

  console.log("Feed created!", await aggregator.loadData());

  return aggregator;
}

createFeed();

Adding Switchboard to Cairo Code

To integrate Switchboard with your code, first add the following dependencies to Scarb.toml:

Example Cairo Code for Using Switchboard Values

In the module, use the latest result function to read the latest data for a feed.

Executing updates in TypeScript

To get the update data for a feed, use the following code:

This implementation allows you to read and utilize Switchboard data feeds within Cairo. If you have any questions or need further assistance, please contact the Switchboard team.

DISCLAIMER: ORACLE CODE AND CORE LOGIC ARE AUDITED - THE AUDIT FOR THIS ON-CHAIN ADAPTER IS PENDING

Last updated