Lesson 4: Remix Fund Me (Price feeds) #5437
-
I'm using the following code provided at https://docs.chain.link/data-feeds/using-data-feeds: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Sepolia
* Aggregator: BTC/USD
* Address: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43
*/
constructor() {
priceFeed = AggregatorV3Interface(
0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43
);
}
/**
* Returns the latest price.
*/
function getLatestPrice() public view returns (int) {
// prettier-ignore
(
/* uint80 roundID */,
int price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed.latestRoundData();
return price;
}
}
Everything working great. But I was trying to experiment and changing the price feed from BTC/USD to ETH/USD, I started facing an error. This is the code with the change: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Sepolia
* Aggregator: ETH/USD
* Address: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
*/
constructor() {
priceFeed = AggregatorV3Interface(
0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
);
}
/**
* Returns the latest price.
*/
function getLatestPrice() public view returns (int) {
// prettier-ignore
(
/* uint80 roundID */,
int price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed.latestRoundData();
return price;
}
}
And this is the error I'm getting:
Why is that happening and what can I do to solve it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Nevermind, I saw my mistake. On the https://docs.chain.link/data-feeds/using-data-feeds, instead of getting the address from Sepolia Testnet's table, I got from Ethereum Mainnet table. So instead of using: "0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419", I should be using: "0x694AA1769357215DE4FAC081bf1f309aDC325306". Attaching it to the code: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Sepolia
* Aggregator: ETH/USD
* Address: 0x694AA1769357215DE4FAC081bf1f309aDC325306
*/
constructor() {
priceFeed = AggregatorV3Interface(
0x694AA1769357215DE4FAC081bf1f309aDC325306
);
}
/**
* Returns the latest price.
*/
function getLatestPrice() public view returns (int) {
// prettier-ignore
(
/* uint80 roundID */,
int price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed.latestRoundData();
return price;
}
} |
Beta Was this translation helpful? Give feedback.
Nevermind, I saw my mistake.
On the https://docs.chain.link/data-feeds/using-data-feeds, instead of getting the address from Sepolia Testnet's table, I got from Ethereum Mainnet table.
So instead of using: "0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419", I should be using: "0x694AA1769357215DE4FAC081bf1f309aDC325306".
Attaching it to the code: