本頁面使用機器翻譯自英語,可能包含錯誤或不清楚的語言。如需最準確的信息,請參閱英文原文。由於更新頻繁,部分內容可能與英文原文有出入。請加入我們在 Crowdin 上的努力,幫助我們改進本頁面的翻譯。 (Crowdin translation page, Contributing guide)
RedStone
概覽
RedStone 是一個模組化預言機網路,負責向智慧合約提供價格資料。在 Kaia 上,RedStone 公開了 Push 饋送,這些饋送將價格資料儲存於鏈上,因此 dApp 可以透過熟悉的、與 Chainlink 相容的 AggregatorV3Interface 讀取這些資料。
RedStone Push 會根據可設定的 偏差 和 心跳 條件,定期更新鏈上價格。請參閱 RedStone Push 文件 以了解更多資訊,並在 Push Feeds 使用者介面 中瀏覽 Kaia 的即時資訊流。
在 Kaia 上使用 RedStone
每個 Push 資料饋送皆以價格饋送合約的形式部署,該合約實作了 Chainlink 的 Aggregator 介面。您可以呼叫 latestRoundData() 來讀取最新價格。
// SPDX-License-Identifier: MITpragma solidity ^0.8.20;interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound );}contract RedStoneConsumer { AggregatorV3Interface public immutable priceFeed; constructor(address feedAddress) { priceFeed = AggregatorV3Interface(feedAddress); } function getLatestPrice() external view returns (int256 price, uint256 updatedAt) { (, price, , updatedAt, ) = priceFeed.latestRoundData(); }}
請傳入您所需資產的饋送網址(請參閱下表)。請務必驗證 updatedAt,並根據您所採用協議的資料新鮮度要求對資料進行四捨五入。