【发布时间】:2022-11-17 03:58:32
【问题描述】:
初学者在这里提前道歉。
我正在学习 Solidity 并使用 Hardhat,并试图弄清楚如何在部署后返回本教程合约中的 Chainlink 喂价值。我知道如何在 remix 中返回函数输出,但无法弄清楚如何在 Hardhat 中使用 console.log 或其他方法。我能够将 console.log 用于令牌地址等内置函数,但无法弄清楚如何应用于其他函数。这是使用 Goerli Testnet 顺便说一句。
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract TestChainlink {
AggregatorV3Interface internal priceFeed;
constructor() {
// ETH / USD
priceFeed = AggregatorV3Interface(0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e);
}
function getLatestPrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
// for ETH / USD price is scaled up by 10 ** 8
return price;
}
}
I tried emulating console.log usage that work for built in functions like token address to apply them to the Chainlink getLatestPrice() function.
const Token = await ethers.getContractFactory("TestChainlink");
const token = await Token.deploy();
console.log("Token address:", token.address);
i.e.
What I tried:
console.log("ETH Price:", getLatestPrice());
【问题讨论】:
标签: solidity hardhat chainlink