[Bug]: sample Contract of data feeds in solidity is failing to fetch latestRounddata.
Opened this issue · 13 comments
Describe the bug
Error on Remix IDE in getting the latestRoundData.
decoded output | { "error": "Failed to decode output: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)" }
Snippet of error
`
from | 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 -- | -- to | DataConsumerV3.getChainlinkDataFeedLatestAnswer() 0xd9145CCE52D386f254917e481eB44e9943F39138 execution cost | 5105 gas (Cost only applies when called by a contract) input | 0xbea...4dfb5 decoded input | {}decoded output | { "error": "Failed to decode output: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)" }
logs | []call to DataConsumerV3.getChainlinkDataFeedLatestAnswer errored: Error occurred: revert.revert
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
You may want to cautiously increase the gas limit if the transaction went out of gas.creation of DataConsumerV3 pending...
`
To Reproduce
Steps to reproduce:
- Go to https://docs.chain.link/data-feeds/using-data-feeds#solidity.
- Open the below mentioned code in Remix. (Click to Open in Remix under solidity code).
`// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
/**
- THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED
- VALUES FOR CLARITY.
- THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
- DO NOT USE THIS CODE IN PRODUCTION.
*//**
- If you are reading data feeds on L2 networks, you must
- check the latest answer from the L2 Sequencer Uptime
- Feed to ensure that the data is accurate in the event
- of an L2 sequencer outage. See the
- https://docs.chain.link/data-feeds/l2-sequencer-feeds
- page for details.
*/contract DataConsumerV3 {
AggregatorV3Interface internal dataFeed;/** * Network: Sepolia * Aggregator: BTC/USD * Address: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 */ constructor() { dataFeed = AggregatorV3Interface( 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 ); } /** * Returns the latest answer. */ function getChainlinkDataFeedLatestAnswer() public view returns (int) { // prettier-ignore ( /* uint80 roundID */, int answer, /*uint startedAt*/, /*uint timeStamp*/, /*uint80 answeredInRound*/ ) = dataFeed.latestRoundData(); return answer; }
}
`
- Compile and deploy the smart contract.
- Click on
getChainlinkDataFeedLatestAnswer
button on deployed instance. - Error "error": "Failed to decode output: Error: data out-of-bounds
URLs
https://docs.chain.link/data-feeds/using-data-feeds#solidity
Expected behavior
The latestRoundData function must return five values representing information about the latest price data.
Additional context
Is it due to using of old contract hash ?
Hey @sandeepV2, I followed the steps you stated above and successfully got back the price from the priceFeed contract.
Here, I deployed the priceFeed contract to the sepolia testnet
Here, I sent a transaction to read the price on the priceFeed contract I initially deployed
You can see in the below image the price that got returned to me
Thank you @EngrPips for quick response. I am facing this issue with default env set on Remix (VM CONCUN). Should it be different ?
Here, I deployed the priceFeed contract to the sepolia testnet
Does sepolia testnet need connecting to wallet with some test ethers/tokens ?
I used the Cancun
evm version as well, and yeah, to deploy and test on the sepolia test net, you need to connect to a wallet with some sepolia ether balance on it.
Hmm @EngrPips interesting, Let me share the exact step of failures with screenshots.
- Go to https://docs.chain.link/data-feeds/using-data-feeds#solidity and Click on Open in Remix.
Screenshot of opened remix tab. (Note compilation is successful).
![Screenshot 2024-05-12 at 5 58 03 PM](https://private-user-images.githubusercontent.com/52043035/329849616-f17d220d-42cf-4362-81d6-a051b00a2132.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4OTcwNzAsIm5iZiI6MTcyNDg5Njc3MCwicGF0aCI6Ii81MjA0MzAzNS8zMjk4NDk2MTYtZjE3ZDIyMGQtNDJjZi00MzYyLTgxZDYtYTA1MWIwMGEyMTMyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDAxNTkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE1MDNiM2UwYTRmNzVkYTNiMTI5NzUxYTVkNGFkMmQ3MTQzYWZhYmE1NDU3NjJhOGQ4Yjk4N2RiZTk4ZTI5MWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TTSB3y3qWsdYgsMFNHqcivvrCOU2WaiMQbySpEiPpiw)
- Go to Deploy & run transactions tab and deploy the contract.
![Screenshot 2024-05-12 at 6 00 42 PM](https://private-user-images.githubusercontent.com/52043035/329849844-54eec56b-9b42-414a-831f-7b774c9c7725.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4OTcwNzAsIm5iZiI6MTcyNDg5Njc3MCwicGF0aCI6Ii81MjA0MzAzNS8zMjk4NDk4NDQtNTRlZWM1NmItOWI0Mi00MTRhLTgzMWYtN2I3NzRjOWM3NzI1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDAxNTkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRmNjdmNGYyZmQ4ZDNmNjRlNDAwNDFlOThlNmFkY2YxYmJhNDFhOGU3OTdkNWE1ZThhMWI3ZTE3NWM3OTA5NjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wlkMjfuVOaLkjqgi4uU1QFUiW3MZIqszsFXEcQnf9YU)
- Deployment is successful, find the details of contract address and logs.
![Screenshot 2024-05-12 at 6 03 07 PM](https://private-user-images.githubusercontent.com/52043035/329849915-9e1fc1d8-85d6-40af-80ea-485e415704b8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4OTcwNzAsIm5iZiI6MTcyNDg5Njc3MCwicGF0aCI6Ii81MjA0MzAzNS8zMjk4NDk5MTUtOWUxZmMxZDgtODVkNi00MGFmLTgwZWEtNDg1ZTQxNTcwNGI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDAxNTkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMzNzk5MDZlYjUwNzY0ODMyOTNmMDQ0NDc4M2Y1NjU1Zjc3NWNjZTY5ZmE3MDc1MzMxNTc0MzcwMDE2NGFiNDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.iaYj7BgPHflQPW56uXoEgEWNdCKMmv8v_NXwzWHrw-4)
- Copy the deployed contract address and input into At Address. we will see another instance of deployed contract below.
![Screenshot 2024-05-12 at 6 05 08 PM](https://private-user-images.githubusercontent.com/52043035/329850035-7eb02871-9c47-449e-ab11-70b076d5e5fd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4OTcwNzAsIm5iZiI6MTcyNDg5Njc3MCwicGF0aCI6Ii81MjA0MzAzNS8zMjk4NTAwMzUtN2ViMDI4NzEtOWM0Ny00NDllLWFiMTEtNzBiMDc2ZDVlNWZkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDAxNTkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVmNDk5Yzg5ZDNjYjU5ZTZmMmRjOWYwNzAwNDlhZjVkN2E4ZjhjYzMzZDY4OTU4NjQyYTBlOWU0YTkxNzU5ZjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.bdZjVLArBcx2w9GiKiWmDOuJQHrrejwZUJhcveyMM9I)
- Click on getChainlinkDataFeedLatestAnswer button. You will get the mentioned error in the description.
![Screenshot 2024-05-12 at 6 06 29 PM](https://private-user-images.githubusercontent.com/52043035/329850132-4e08f510-0992-4d1a-98ba-d3e614247b60.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ4OTcwNzAsIm5iZiI6MTcyNDg5Njc3MCwicGF0aCI6Ii81MjA0MzAzNS8zMjk4NTAxMzItNGUwOGY1MTAtMDk5Mi00ZDFhLTk4YmEtZDNlNjE0MjQ3YjYwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDAxNTkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTRkNDY2ZmI1YTZkZDU4ZjI3ZDE0NzI5N2NkN2VmMGNlMmM5MzJkMzc5YTMyNGEwMDUzOTJhYzYxNWQ2MmQzNzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.ptkusH9OyR0OqrWn7uYb8Mr_cNy4fDuZQNm7PFe99b0)
Error :
`
CALL[call]from | 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 -- | -- to | DataConsumerV3.getChainlinkDataFeedLatestAnswer() 0xd9145CCE52D386f254917e481eB44e9943F39138 execution cost | 5105 gas (Cost only applies when called by a contract) input | 0xbea...4dfb5 decoded input | {} decoded output | { "error": "Failed to decode output: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)" } logs | []from: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4to: DataConsumerV3.getChainlinkDataFeedLatestAnswer()data: 0xbea...4dfb5Debug`call to DataConsumerV3.getChainlinkDataFeedLatestAnswer errored: Error occurred: revert.
I get the same error while interacting with initially deployed instance too, Let me know if am missing something here ?
Did you connect the Remix to Metamask?
Nope i did not connect any wallet. Opened fresh tab with (Open in Remix) button.
When you get to Remix, connect the Remix to your metamask[ sepolia network], then deploy the contract. If you do so, it will work when you try to get the price. You are deploying to the Remix chain and there is no chainlink pricefeed on the Remix local chain that would send price details to you.
When you get to Remix, connect the Remix to your metamask[ sepolia network], then deploy the contract. If you do so, it will work when you try to get the price. You are deploying to the Remix chain and there is no chainlink pricefeed on the Remix local chain that would send price details to you.
I used the Cancun evm version as well, and yeah,
You did mention that it worked for Cancun evm too.
HI @sandeepV2
Were you able to deploy your contract to Ethereum Sepolia and test the data feed?
@aelmanaa, Do you have any difficulty deploying to Ethereum Sepolia and testing the data feed?
@sandeepV2, I switch Environment to Remix VM - Sepolia fork and it works fine