Comment on page
On-Chain Oracle (Solana)
Our API can be consumed via a Switchboard 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:
- 2.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: https://api.tensor.so/sol/collections/9uBX3ASjxWvNBAD1xjbVaKA74mWGZys3RGSF7DdeDD3F/floor
- 3.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:
- Go into
rust/tests/lendoor.tsand update the
aggregatoraccount marked with a TODO to your own
anchor test --skip-deploy
- Follow the link printed to the console and read the logs! You should see something like this:
> Program log: Instruction: GimmeLoan
> Program log: GM and Welcome to LENDOOR Inc.
> Program log: Hm, looks like you want a loan against your SMB!
> Program log: Let's see what the big brains at Tensor are saying re SMB prices...!
> Program log: They claim the SMB Smart Floor is at 120.78269948242 SOL.
> Program log: Smart floor is a robust version of normal floor prices, designed specifically for financial use-cases like NFT lending and NFT derivatives. So we can trust it.
> Program log: I'd be prepared to give you a loan at 75% LTV, making it 90.587024611815 SOL!
> Program log: Whacha say, ser?
> Program HX7h7LUQ61ztLgXg4Hh4fqnvuWSuf1vVoh7SMdtarpiU consumed 8974 of 200000 compute units
- Now let's do an off-chain, js app:
- Go to
- Update the aggregator pubkey similarly where it's marked with a TODO
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! 🛠