Skip to main content

The SwitchboardProgram class provides a high-level API to interact with the Switchboard smart contracts on the EVM.

This class provides methods to send transactions, poll events, fetch accounts, and more. It requires a Signer or Provider instance and the address of the Switchboard contract to instantiate.

// Instantiate SwitchboardProgram
const signer = new ethers.Wallet(privateKey);
const switchboardProgram = await SwitchboardProgram.load(
signer, // Signer instance
"0x73d6C66874e570f058834cAA666b2c352F1C792D" // Switchboard contract address
);

// Send a transaction to Switchboard
const tx = await switchboardProgram.sendSbTxn("createOracleQueue", [
name,
authority,
unpermissionedFeedsEnabled,
maxSize,
reward,
oracleTimeout,
]
);

// Fetch all aggregator data for a given authority
const authority = '0xabc123...'; // the public key of the authority
const aggregatorData = await switchboardProgram.fetchAggregators(authority);

// Connect a new signer to SwitchboardProgram
const newSigner = new ethers.Wallet(newPrivateKey);
const newSwitchboardProgram = switchboardProgram.connect(newSigner);

Implemented by

Index

Properties

address

address: Promise<string>

A getter that returns a promise which resolves to the address of the signer. If the address has already been fetched, it will be returned from the cache.

@returns

Promise

<string>

const signerAddress = await switchboard.address;

chainId

chainId: Promise<number>

fetchFunctions

fetchFunctions: () => Promise<LoadedFunctionAccount[]>

Type declaration

    • Fetches all functions for the Switchboard contract.


      Returns Promise<LoadedFunctionAccount[]>

      An array of LoadedFunctionAccount’s.

      // Fetch all function data for a given authority
      const authority = '0xabc123...'; // the public key of the authority
      const functionAccounts = await switchboardProgram.fetchFunctions(authority);

      // Now you can loop through the functionAccounts array to access individual data.
      for (const account of functionAccounts) {
      console.log(account.data);
      }

fetchFunctionsByAuthority

fetchFunctionsByAuthority: (_authority?: string) => Promise<LoadedFunctionAccount[]>

Type declaration

    • Fetches an array of FunctionData instances for a given authority.


      Parameters

      • optional_authority: string

      Returns Promise<LoadedFunctionAccount[]>

      An array of LoadedFunctionAccount’s.

      // Fetch all function data for a given authority
      const authority = '0xabc123...'; // the public key of the authority
      const functionData = await switchboardProgram.fetchFunctions(authority);

      // Now you can loop through the functionData array to access individual data.
      for (const data of functionData) {
      console.log(data);
      }

getEnclaveAuthorityMrEnclave

getEnclaveAuthorityMrEnclave: (enclaveAuthority: string) => Promise<Uint8Array>

Type declaration

    • (enclaveAuthority: string): Promise<Uint8Array>
    • Fetch the MrEnclave measurement for a given enclave authority address.


      Parameters

      • enclaveAuthority: string

        The address of the enclave authority to fetch a measurement for.

      Returns Promise<Uint8Array>

      A enclave authorities MrEnclave measurement

      const mrEnclave = await switchboardProgram.getEnclaveAuthorityMrEnclave('0xMyEnclaveAuthority');

pollTxnForSbEvent

pollTxnForSbEvent: PollTxnForEventFieldFn

Polls a Switchboard contract transaction for an emitted event field

@param

The contract transaction to poll

@param

An optional field name to extract from the event

@returns

Promise

<T>

const accountAddress: string = await switchboardProgram.pollTxnForSbEvent(tx, 'accountAddress');

sb

sb: Switchboard

sbPushOracle

sbPushOracle: Promise<SwitchboardPushReceiver>

sendSbTxn

sendSbTxn: SendContractMethod<Switchboard>

Sends a transaction to the Switchboard.sol contract

@param

The name of the contract method to be called

@param

The arguments to pass to the contract method

@param

The options to pass to the contract method

@returns

Promise

<ContractTransaction>

const transaction = await switchboardProgram.sendSbTxn('methodName', args, options);

Methods

connect

  • Returns a new instance of the SwitchboardProgram with a new signer.


    Parameters

    • signer: Signer

      The new signer

    Returns ISwitchboardProgram

    SwitchboardProgram

    const newSwitchboardProgram = switchboardProgram.connect(newSigner);