Skip to main content

The SwitchboardProgram class provides a high-level API to interact with the Switchboard and SwitchboardAttestationService 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);

Implements

Index

Constructors

constructor

Properties

publicreadonlysb

sb: Switchboard

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);

Accessors

address

  • get 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>

    Promise

    <string>

    const signerAddress = await switchboard.address;

publicchainId

  • get chainId(): Promise<number>
  • Returns Promise<number>

publicsbPushOracle

  • get sbPushOracle(): Promise<SwitchboardPushReceiver>
  • Returns Promise<SwitchboardPushReceiver>

Methods

publicconnect

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


    Parameters

    • signer: Signer

      The new signer

    Returns SwitchboardProgram

    SwitchboardProgram

    const newSwitchboardProgram = switchboardProgram.connect(newSigner);

publicfetchFunctions

  • 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);
    }

publicfetchFunctionsByAuthority

  • 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);
    }

publicgetEnclaveAuthorityMrEnclave

  • getEnclaveAuthorityMrEnclave(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');

publicpollTxnForSbEvent

  • pollTxnForSbEvent<T>(tx: ContractTransaction, field?: string): Promise<T>
  • Polls a Switchboard contract transaction for an emitted event field


    Type parameters

    • T

    Parameters

    • tx: ContractTransaction

      The contract transaction to poll

    • optionalfield: string

      An optional field name to extract from the event

    Returns Promise<T>

    Promise

    <T>

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

publicstaticfromProvider

  • Static method to create and return a SwitchboardProgram instance.

    @throws

    if chainId is not supported by Switchboard


    Parameters

    • provider: Provider

    Returns Promise<SwitchboardProgram>

    Promise

    <SwitchboardProgram>

    const switchboardProgram = await SwitchboardProgram.load(mySignerOrProvider, '0xMySwitchboardAddress');

publicstaticload

  • Static method to create and return a SwitchboardProgram instance.


    Parameters

    • signerOrProvider: any

      The signer or provider used to interact with the contracts

    • switchboardAddress: string

      The contract address of the Switchboard

    Returns Promise<SwitchboardProgram>

    Promise

    <SwitchboardProgram>

    const switchboardProgram = await SwitchboardProgram.load(mySignerOrProvider, '0xMySwitchboardAddress');