Solana Token Price from offchain data

Hello Solana Developers,

I want to create an SPL-Token and its price will be changed at certain frequency by some offchain calculations. how can I achieve this?

I believe what you are wanting is what they call an “oracle”. An oracle, in a blockchain context, means some service that is responsible for taking data outside of the chain, and putting it on the chain so that on-chain programs can access it.

I don’t have any personal experience yet with oracles in Solana yet, but I imagine that it could be quite simple to implement.

It could look something like this:

  • Create a smart contract that has a transaction for writing the calculated price to an on-chain account
  • The contract will be designed so that it only trusts one keypair to set the price
  • This keypair will be given to whatever service you have that does the off-chain calculations
  • Your service will use the keypair and send a transaction to the smart contract to update the price whenever at your certain frequency
  • This price will be readable by any other smart contracts on the chain and can be used to adjust your price however

I’m not positive this is the best way to do it or not, but I think it is simple enough and would work.

Otherwise you may find it useful to look into other oracles that are integrated with Solana. Searching for “oracle” on the Solana ecosystem page shows some possibilities. At the same time, these may be overkill for your use-case and a simpler approach might be beneficial.