Pyth on Neon EVM: Real-time Market Data Oracle
Decentralized Finance (DeFi) has been revolutionizing the way people around the world interact with their money. Many of its innovative capabilities are based on its ability to integrate high-fidelity, time-sensitive, real-world data, including data from off-chain sources.
This data is typically supplied by oracles, entities that feed external data to a blockchain. That’s where Pyth comes in.
Pyth is an open-source, real-time on-chain market data feed that supports the Neon EVM. Pyth currently supports price feed for select cryptocurrency, foreign exchange, precious metal, and equity pairs, and its source code is publicly available on GitHub.
How to Use Pyth With the Neon EVM
Let’s dive into how to make Pyth price feeds available for your Neon dApp. We’ll do this by considering a simple smart contract involving Pyth on the Neon EVM.
Before we begin, It is important to note that the Pyth team strongly recommends its users to follow its consumer best practices when consuming Pyth data.
In the following simple Solidity smart contract, the function getBTCUSDPrice() returns the price from the BTC/USD price feed for the Neon Devnet. For a different price feed, refer to the Pyth website for both Devnet and Mainnet, find the price feed, and use the corresponding price feed ID (the priceID variable below). Alternatively, you could also search for your desired price feed here.
How to Deploy
To deploy your smart contract with Pyth oracle integration using Truffle, follow these steps:
- Create a .secret file containing the private key or mnemonic of the account you want to use to deploy the contracts.
- Optional: Edit the truffle-config.js file to add the Neon network you want to deploy to.
- Run truffle migrate — network neon_devnet
Pyth plays a crucial role in the Neon ecosystem. By providing a feed of high-quality external data, it allows for accurate and real-time asset pricing on the Neon EVM. Without this oracle, activities such as decentralized swaps on Neon would be impossible. With Pyth, developers on Neon can make their smart contracts work even smarter.
First, add the necessary Pyth imports.