【发布时间】:2021-09-25 18:29:56
【问题描述】:
这是我第一次在 Remix 上部署合约以及学习如何在 Solidity 上编码。
我已经阅读了guide 并成功部署了提供的智能合约模板:
pragma solidity ^0.6.7;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: BTC/USD
* Address: 0x6135b13325bfC4B00278B4abC5e20bbce2D6580e
*/
constructor() public {
priceFeed = AggregatorV3Interface(0x6135b13325bfC4B00278B4abC5e20bbce2D6580e);
}
/**
* Returns the latest price
*/
function getThePrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}
然而,我以为在部署了上面的模板之后,每当我点击getLatestPrice button时,这种货币对的价格就会立即更新,我错了,第一次点击后价格竟然被“冻结”了.
所以,我想知道在上面的模板中必须输入什么来实现这个目标
另外,我尝试通过在return price; 正下方键入return timeStamp; 来打印timeStamp,但在编译时,Remix 编译器回复:
TypeError:返回参数类型 uint256 不能隐式转换为预期类型(第一个返回变量的类型)int256。返回时间戳; ^-------^
所以,出于好奇,我如何将 uint256 变量转换为 int256 变量以获得每个更新价格的时间戳(每次点击getLatestPrice button)?
感谢阅读
【问题讨论】:
-
通常情况下,您希望每个 stackoverflow 问题有 1 个问题。你能再为你的第二个问题再做一个吗?
-
好的,@PatrickCollins 先生,我刚刚成功,在这里:stackoverflow.com/questions/68422733/…
-
可爱,谢谢!
标签: javascript solidity smartcontracts chainlink