本页面使用机器翻译自英语,可能包含错误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容 可能与英文原文有出入。请加入我们在 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,并根据协议对数据的新鲜度要求对数据进行四舍五入处理。