Crypto Price Feed

Example Crypto Price Feed

Using Pyth Core or a public API to build and deploy a crypto feed on SEDA Fast or SEDA Core.

Contents


Requirements

rustup target add wasm32-wasip1

Alternatively, use the devcontainerarrow-up-right for a pre-configured environment.

Additional Requirement for SEDA Fast

magnifying-glass
  • SEDA Fast requires a FAST API key for querying.

  • SEDA Core does not require a FAST API key, but instead requires submitting a Data Request onchain from a supported network or on SEDA Chain directly.

circle-info

If you need more than 7 days for your trial key, please reach out to our team on Discordarrow-up-right for an extended free trial.


Getting Started

The easiest way to start building a SEDA Oracle Program is by using the seda-starter-kit. This starter kit offers a streamlined setup process and comes with the essential tools and structure to help you create and deploy your first Oracle program on the SEDA network.

Clone and checkout the repository:

Install dependencies:

Copy and populate the .env file's MNEMONIC:

circle-info

If you need a SEDA mnemonic this can most easily be achieved by downloading Keplr walletarrow-up-right. You can then claim Testnet SEDA tokens at the SEDA faucetarrow-up-right


Building the Oracle Program

The PriceFeed Oracle Program is divided into two phases:

Execution: Fetches the price of an asset pair (e.g., BTC-USDT or a Pyth asset ID) from an external source and processes the data.

Tally: Aggregates execution reports.

🔎 Difference:

  • SEDA Fast: Typically runs a single executor and forwards the result.

  • SEDA Core: Multiple Overlay Nodes execute the program, and the tally phase aggregates (e.g., median) results.


Step 1: Entrypoint

The Oracle Program logic lives in the src folder, where main.rs serves as the entry point.

src/main.rs

This setup initializes the PriceFeed Oracle program and links the execution and tally phases that make up the data request.


Step 2: Execution Phase

The execution phase is where the Oracle Program fetches data and performs computation on the fetched data.

Pyth Core via SEDA Data Proxy

Start by defining inputs and outputs:

Parse input:

Create src/fetch_pyth.rs

Define response structures and fetch logic:

Update execution phase:

circle-info
  • This example uses proxy_http_fetch and a signed SEDA Data Proxy.

  • Suitable for both Fast and Core.

  • In Fast, the result is typically forwarded directly.

  • In Core, results are revealed and aggregated in tally phase.


Calling a Public API via http_fetch

Check for errors:

Parse and compute:


Step 3: Tally Phase


SEDA Fast Tally Phase (Single Executor Forwarding)

circle-info
  • SEDA Fast only has one executor.

  • The first reveal is used and forwarded.


SEDA Core Tally Phase (Median Aggregation)

circle-info

SEDA Core Behavior:

  • Multiple Overlay Nodes execute.

  • Tally phase aggregates (median).

  • Big-endian encoding for EVM compatibility.


Building the Oracle Program

To build:


Deploying

SEDA Fast Deployment

Query:


SEDA Core Deployment

After building, you'll have the .wasm artifacts in the build directory.

These artifacts can be deployed to the SEDA network and referenced in onchain Data Requests from supported networks.

Differences between SEDA Core and Fast:

Component
SEDA Fast
SEDA Core

Execution Replication

Single executor

Multiple Overlay Nodes

Tally Behavior

Forward first reveal

Aggregated consensus (e.g. median)

Access Method

Authenticated REST API

Onchain Data Request

Encoding

JSON common

Big-endian for EVM

The Oracle Program logic remains portable between both delivery methods.

Last updated

Was this helpful?