Crypto Data Feed
Using Pyth Core to build and deploy a crypto feed on SEDA Fast.
Contents
Requirements
Bun: Install Bun for package management and building.
Rust: Install Rust for development and building.
WASM: Install the
wasm32-wasip1target withrustup target add wasm32-wasip1for WASM compilation.Alternatively, use the devcontainer for a pre-configured environment.
A SEDA FAST developer key. Visit the Developer Page here and access a 7 day trial.
If you need more than 7 days for your trial key, please reach out to our team on Discord for an extended free trial.
Getting Started
Clone and checkout the seda-starter-kit repository:
git clone https://github.com/sedaprotocol/seda-starter-kit.git simple-price-feed; cd simple-price-feedBun install:
bun installCopy and populate the .env file's MNEMONIC .
If you need a SEDA mnemonic this can most easily be achieved by downloading Keplr wallet. You can then claim Testnet SEDA tokens at the SEDA faucet
Build your Crypto Feed
Start by navigating to the src/execution_phase.rs file. The execution phase contains the main computational component of your FAST feed. This phase dictates how data is fetched and aggregated. The src/tally_phase.rs is more important for feeds that require onchain delivery via SEDA Core or that need to be backwards compatible with a SEDA Core feed.
The first step of the program is to define which inputs will be called. In this example we will use Pyth Core as a data source for this feed. We need to know what Pyth Asset ID we want to fetch. Navigate to https://insights.pyth.network/price-feeds and select a feed. For this example I will take BTC/USD with asset ID 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 .
We expect a stringified price as the output:
Next we parse the input and set a placeholder response for the time being:
Now we have to fetch the price from Pyth. For this we are going to use a SEDA Data Proxy. SEDA hosts Pyth Hermes testnet proxy at: http://pyth.proxy.testnet.seda.xyz/proxy
with public key: 033ed60cfdeb7e91f718bf28e514e5c2f2990400b4643e86856e530de9b46dfb47
Lets create src/fetch_pyth.rs to hold all our data fetching logic.
We then add fetch_pyth to src/main.rs so it can be accessed from our execution phase
Now update execution_phase.rs to fetch the data using fetch_pyth and return the result:
Now we just alter tally_phase.rs to simply verify that our response is formatted correctly, and then forward it as is:
We can now deploy the feed and start querying it:
Which should result in something like:
tx
06C4205396F6480F807A9A7B51D9C159C96E59A32C7D6DEA12F9F56C7051CC2A
oracleProgramId
e87808ce3f0809314e92a604164df5312cec84b4f0256c9af0a92000141f53c9
You can then query the fast oracle by calling:
What's Next
Add additional computation to your feed:
Unit conversion on the Pyth price (take the expo + price and convert it)
Handle confidence intervals
Add a separate quote asset to the Input
Query the quote asset additionally to the base asset
Add a cross-rate for the base asset from e.g. USD -> USDC
Last updated
Was this helpful?

