Using Switchboard: Creating Custom Data Feeds

Build Job Definition

Data Sources

A data feed should have multiple sources but for this example we’ll keep it simple. We’ll be using the api.weather.gov/gridpoints endpoint to resolve our data feed. After doing some digging we’ve determined that the weather forecast office should be MFL and the latitude and longitude should be 111 and 50 respectively. So our full API endpoint should be https://api.weather.gov/gridpoints/MFL/111,50/forecast. We’ll pass this URL as the argument to the httpTask.

Parse Response

Now we need to extract the value from the API response. Here is what the response will look like:

Build Task Definitions

Now we can put it all together. The httpTask will be used to fetch external data, then pass it to the jsonParseTask to extract the latest temperature value. The final definition will look like this:

Build Data Feed

When building a Switchboard data feed, you will need to create the following accounts:

  • Job(s) — to store each job definition (only one needed for our example)
  • Lease — to pre-fund oracles for any update request
  • Permission — permits an aggregator to use a set of oracles

Configure Data Feed

Connect your wallet, then locate and select the Custom Feed button. The following popup lets you configure the name of your feed, as well as the job definitions. Our example uses a single job.

Create Data Feed

You should have the weather feed in your basket and ready for checkout.

Conclusion

Switchboard allows developers to build and configure their own on-chain data feeds. If you’re building with Switchboard and need a new task type or additional functionality please reach out to us on Discord, Telegram, or Twitter.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store