Build with TypeScript

Design, simulate, and publish Switchboard feed definitions using TypeScript (Solana and EVM compatible patterns).

This guide is for developers who prefer code-first workflows.

You’ll learn how to:

  • model a feed as a list of Oracle Jobs

  • compose each job from sequential Tasks

  • simulate jobs using Crossbar

  • iterate safely and build production-grade feed definitions

This guide focuses on designing + simulating feed definitions. Deployment differs by chain — see Deploy Feed.


Mental model

Oracle Jobs are “pipelines”

A job is an ordered list of tasks:

// Oracle Job
[
  httpTask,
  jsonParseTask,
  multiplyTask,
]

Each task runs sequentially. The job’s “current value” is updated as tasks run, and the job result is valid only if the final task produces a numeric value.

Feeds are “job sets”

A feed is a set of jobs. Oracles execute the jobs and then aggregate the results (commonly median across jobs).


Prerequisites

  • Node.js or Bun (examples use Bun for simple TS execution)

  • Basic TypeScript familiarity

  • Your data sources (REST APIs, DEX pricing tasks, etc.)


Install dependencies

Using Bun

Note: Some examples import OracleJob from @switchboard-xyz/common. Adding it explicitly avoids “transitive dependency” surprises.


Example: a minimal BTC/USDT job

This is the smallest “real” job: fetch a JSON payload and extract a price.

Create index.ts:

At this point you have a valid feed definition (one job).


Simulate your job(s) with Crossbar

Simulation runs your jobs against real sources and returns their outputs. This is how you iterate quickly before deploying or publishing.

⚠️ The public simulation endpoint is heavily rate-limited. Use it for development only.

Append this to index.ts:

Run it:

You should see a response like:


Building production-grade feeds

Use multiple jobs (multiple sources)

The simplest reliability upgrade is to use several independent jobs:

  • Job 1: CEX API

  • Job 2: another CEX API

  • Job 3: on-chain DEX price simulation task

Then rely on aggregation (median) and feed configuration (variance/quorum) to filter noise.

Conceptually:

Normalize decimals

Different sources often report:

  • different quote assets

  • inverted prices

  • different decimal precision

Use math tasks (multiply/divide/round) so every job returns the same unit.

Bounding can be applied:

  • within a job (reject a single bad API response)

  • at the feed level (reject updates when jobs disagree too much)


Task reference

Switchboard supports many task types, including:

  • HttpTask (REST)

  • JsonParseTask (JSONPath extraction)

  • MedianTask (sub-aggregation inside a job)

  • JupiterSwapTask (Solana DEX price simulation)

  • SecretsTask (secure secret retrieval)

Full task docs:

  • https://protos.docs.switchboard.xyz/


Secrets, variables, and safety

Variable overrides (${VAR_NAME})

Variable overrides let you inject values at runtime.

Critical rule: Only use variables for authentication (API keys/tokens). Do not use variables for anything that changes feed logic (URLs, JSON paths, multipliers), because consumers cannot cryptographically verify what values were injected at runtime.

SecretsTask

If you need to retrieve secrets from a dedicated secrets server at runtime, include a SecretsTask at the top of the job, then use the unwrapped variables in downstream tasks.

(See SecretsTask docs in the task reference above.)


Where to go next

Last updated