Use Oracles in Your Aptos Applications
此内容尚不支持你的语言。
This reference guide presents various Oracles that you can use while building on Aptos. Oracles supply off-chain data to the blockchain, enabling smart contracts to access a diverse range of information. Currently, there are two oracles documented here in this guide: Chainlink and Pyth Network.
Chainlink
Section titled “Chainlink”Chainlink is the industry-standard oracle platform bringing the capital markets on-chain and powering the majority of decentralized finance.
The only all-in-one oracle platform for creating workflows across blockchains and legacy systems while embedding critical data, compliance, and privacy capabilities, which are then represented as a single line of code that runs in a verifiable decentralized runtime.
Many of the world’s largest financial services institutions and DeFi protocols have adopted Chainlink’s standards and infrastructure.
Chainlink Data Feeds
Section titled “Chainlink Data Feeds”By adopting the Chainlink standard for high-quality data, Aptos now has seamless access to the tamper-proof data needed to support the development of highly secure applications on the network.
Chainlink Data Feeds provide a secure, reliable, and decentralized source of real-world data to power unique smart contract use cases across decentralized and traditional finance.
- Data providers aggregate raw price data from a multitude of centralized and decentralized exchanges, accounting for time, volume, and outliers.
- Independent Chainlink nodes fetch market price data from various data providers and combine the results into an aggregated value.
- Multiple Chainlink nodes then aggregate their results together off-chain to generate an ‘oracle report,’ which is made available to smart contracts.
Key Data Feeds developer tools
- Data Feeds on Aptos — view all relevant addresses and details to use Aptos with Data Feeds.
- Data Feeds official documentation — learn how to use Chainlink Data Feeds.
Chainlink CCIP
Section titled “Chainlink CCIP”Chainlink Cross-Chain Interoperability Protocol (CCIP) is the standard for interoperability. CCIP enables developers to build secure cross-chain applications that can transfer tokens, send messages, and initiate actions across blockchains.
Through the Cross-Chain Token (CCT) standard, CCIP enables token developers to integrate new and existing tokens with CCIP in a self-serve manner within minutes, without requiring vendor lock-in, hard-coded functions, or external dependencies that may limit future optionality.
CCTs offer several benefits:
- Self-serve deployments
- Full control and ownership for developers
- Zero-slippage transfers
- Enhanced programmability via configurable rate limits
- Reliability features such as Smart Execution
CCIP is powered by Chainlink decentralized oracle networks (DONs)—a proven standard with a track record of securing tens of billions of dollars and enabling over $25 trillion in on-chain transaction value. Key CCIP developer tools
- CCIP Directory — view all relevant addresses and details needed to use Aptos with CCIP.
- CCIP official documentation — start integrating CCIP into your cross-chain application.
- CCIP Token Manager — an intuitive front-end web interface for the deployment of new and management of existing CCTs by their developers, including no-code guided deployments and configuration tools.
- CCIP SDK — a software development kit that streamlines the process of integrating CCIP, allowing developers to use JavaScript to create a token transfer frontend dApp.
Pyth Network
Section titled “Pyth Network”The Pyth Network is one of the largest first-party Oracle networks, delivering real-time data across a vast number of chains.
The network comprises some of the world’s largest exchanges, market makers, and financial services providers. These publish proprietary data on-chain for aggregation and distribution to smart contract applications.
How to Use Pyth Real-Time Data in Aptos Contracts
Section titled “How to Use Pyth Real-Time Data in Aptos Contracts”This guide explains how to use real-time Pyth data in Aptos applications.
Configuring the Move.toml
file
Section titled “Configuring the Move.toml file”Add the Pyth Contract to your project dependencies in the Move.toml
file:
[dependencies]Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/aptos/contracts", rev = "main" }
The named addresses of pyth
, wormhole
, and deployers
must be defined at compile time. These addresses are used to interact with the Pyth contract on Aptos.
[addresses]pyth = "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387"deployer = "0xb31e712b26fd295357355f6845e77c888298636609e93bc9b05f0f604049f434"wormhole = "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625"
Consult Aptos Contract Addresses for the complete list of contract addresses on different Aptos networks.
Write Contract Code
Section titled “Write Contract Code”The code snippet below provides an example module fetching the BTC/USD price from Pyth price feeds:
module example::example { use pyth::pyth; use pyth::price::Price; use pyth::price_identifier; use aptos_framework::coin;
// Add the pyth_price_update argument to any method on your contract that needs to read the Pyth price. // See https://docs.pyth.network/price-feeds/fetch-price-updates for more information on how to fetch the pyth_price_update. public fun get_btc_usd_price(user: &signer, pyth_price_update: vector<vector<u8>>): Price {
// First update the Pyth price feeds let coins = coin::withdraw(user, pyth::get_update_fee(&pyth_price_update)); pyth::update_price_feeds(pyth_price_update, coins);
// Read the current price from a price feed. // Each price feed (e.g., BTC/USD) is identified by a price feed ID. // The complete list of feed IDs is available at https://pyth.network/developers/price-feed-ids // Note: Aptos uses the Pyth price feed ID without the `0x` prefix. let btc_price_identifier = x"e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"; let btc_usd_price_id = price_identifier::from_byte_vec(btc_price_identifier); pyth::get_price(btc_usd_price_id) }}
The code snippet above does the following things:
- Call
pyth::get_update_fee
to get the fee required to update the Pyth price feeds. - Call
pyth::update_price_feeds
and passpyth_price_update
to update the Pyth price feeds. - Call
pyth::get_price
to read the current price, providing the price feed ID you wish to read.
Additional Resources
Section titled “Additional Resources”You may find these additional resources helpful for developing your Aptos application.
Sponsored Feeds on Aptos
Section titled “Sponsored Feeds on Aptos”The price feeds listed in the table below are currently sponsored in Aptos mainnet.
Update Parameters: 1 second heartbeat or 0.5% price deviation
Name | Price Feed Id |
---|---|
APT/USD | 03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5 |
BTC/USD | e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 |
ETH/USD | ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace |
SOL/USD | ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d |
USDC/USD | eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a |
USDT/USD | 2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b |
CAKE/USD | 2356af9529a1064d41e32d617e2ce1dca5733afa901daba9e2b68dee5d53ecf9 |
SUI/USD | 23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744 |
CETUS/USD | e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef |
BNB/USD | 2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4f |
WBTC/USD | c9d8b075a5c69303365ae23633d4e085199bf5c520a3b90fed1322a0342ffc33 |
THL/USD | 74e3fbb0d33e0ed8c0078b56134dcebdae38852f0858a8ea4de4c5ea7474bd42 |
USDY/USD | e393449f6aff8a4b6d3e1165a7c9ebec103685f3b41e60db4277b5b6d10e7326 |
WETH/USD | 9d4294bbcd1174d6f2003ec365831e64cc31d9f6f15a2b85399db8d5000960f6 |
THAPT/USD | b29276972267db5d64ae718fb7f107ad9e72a79cabf9992f0e9bc75ad451a7f6 |
EZETH/USD | 06c217a791f5c4f988b36629af4cb88fad827b2485400a358f3b02886b54de92 |
WEETH/USD | 9ee4e7c60b940440a261eb54b6d8149c23b580ed7da3139f7f08f4ea29dad395 |
USDM/USD | a6a0dfa49b6b3a93510658245618099f5e842514970f596cf64fad9e0d658193 |
STONE/USD | 4dcc2fb96fb89a802ef9712f6bd2246d3607cf95ca5540cb24490d37003f8c46 |
For more details on sponsored feeds, check here
API Reference
Section titled “API Reference”The Aptos API reference lets you interactively explore the complete API of the Pyth contract.
Example Applications
Section titled “Example Applications”- Minimal on-chain contract, which updates and returns the BTC/USD price from Pyth price feeds.
- Mint NFT, a minting application that uses Pyth price feeds to mint an NFT.