On-Chain Oracle (Solana)
Last updated
Last updated
Our API can be consumed via a oracle on-chain, on Solana. Both Solana NFT and Ethereum NFT prices can be consumed, which means you can build a cross-chain app on Solana that, for example, relies on Punks or BAYC prices from Ethereum.
With the current architecture, it's not possible to have a single Switchboard price feed report all the prices for all collections. Instead a new price feed needs to be configured per collection.
Luckily, configuring a new price feed on Switchboard takes less than 2 minutes, requires no coding, and costs peanuts.
Let us do so step by step Devnet example. We'll configure a price feed for SMBs:
Go to
Click + custom feed
button in the top right hand corner
Give your feed a name, eg "SMB Smart Floor Price"
Click "add a job"
We now need to build a job definition. You can read more about Switchboard's publishers and jobs , or simply follow the below steps:
We need to find out the "collection ID" so we hit the endpoint. The ID for SMBs is 9uBX3ASjxWvNBAD1xjbVaKA74mWGZys3RGSF7DdeDD3F
We now can construct a link for floor prices. Since we only care for the latest price, we can ignore the at=
parameter. The url becomes:
With the url in hand we can finally construct the job:
Copy paste the above job into the window on Switchboard and hit test
. Give it a few sec and hopefully a number appears next to test button. This means our job is working correctly!
Title jour job and hit "add job"
Hit "add feed"
On the right hand side, hit "configure feeds", then "checkout" at the bottom
Make sure you have some SOL in your devnet wallet
Configure the interval (how often you want the price updated) and length (how long will the price feed be live for), then complete the rest of the checkout process by signing relevant transactions
Once completed, you can click "view feeds" - and there it is! Your very own smart floor price oracle for SMBs on Solana!
Now let's use it in an example app.
Let's do an on-chain, rust app first:
Collect the "aggregator public key" from your switchboard UI, mine looks like this: 8VD9EJ4njJfH1o2X2a8HLrx93Qa5noNGYt3qhyzcVZ1S
Go into rust/tests/lendoor.ts
and update the aggregator
account marked with a TODO to your own
Run anchor test --skip-deploy
Follow the link printed to the console and read the logs! You should see something like this:
Now let's do an off-chain, js app:
Go to js/play.ts
Update the aggregator pubkey similarly where it's marked with a TODO
run yarn && yarn play
you should see a single number printed to the console, which is the SMB smart floor price reported by Tensor
And just like that, you can consume smart floor prices on-chain via on oracle!
Happy Solana hacking! 🛠
Go to our repo and git clone it