Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: sample Contract of data feeds in solidity is failing to fetch latestRounddata. #1940

Open
sandeepV2 opened this issue May 11, 2024 · 10 comments
Labels
bug Something isn't working triage

Comments

@sandeepV2
Copy link

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:

  1. Go to https://docs.chain.link/data-feeds/using-data-feeds#solidity.
  2. 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;
}

}
`

  1. Compile and deploy the smart contract.
  2. Click on getChainlinkDataFeedLatestAnswer button on deployed instance.
  3. 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 ?

@sandeepV2 sandeepV2 added bug Something isn't working triage labels May 11, 2024
@EngrPips
Copy link

EngrPips commented May 11, 2024

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
Screenshot 2024-05-11 at 21 17 14

Here, I sent a transaction to read the price on the priceFeed contract I initially deployed
Screenshot 2024-05-11 at 21 17 42

You can see in the below image the price that got returned to me
Screenshot 2024-05-11 at 21 18 20

@sandeepV2
Copy link
Author

sandeepV2 commented May 12, 2024

Thank you @EngrPips for quick response. I am facing this issue with default env set on Remix (VM CONCUN). Should it be different ?
Screenshot 2024-05-12 at 10 36 55 AM

Here, I deployed the priceFeed contract to the sepolia testnet

Does sepolia testnet need connecting to wallet with some test ethers/tokens ?

@EngrPips
Copy link

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.

@sandeepV2
Copy link
Author

Hmm @EngrPips interesting, Let me share the exact step of failures with screenshots.

  1. 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
  1. Go to Deploy & run transactions tab and deploy the contract.
Screenshot 2024-05-12 at 6 00 42 PM
  1. Deployment is successful, find the details of contract address and logs.
Screenshot 2024-05-12 at 6 03 07 PM
  1. 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
  1. Click on getChainlinkDataFeedLatestAnswer button. You will get the mentioned error in the description.
Screenshot 2024-05-12 at 6 06 29 PM

Error :
`

CALL[call]
from: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
to: DataConsumerV3.getChainlinkDataFeedLatestAnswer()
data: 0xbea...4dfb5
Debug
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.
`

@sandeepV2
Copy link
Author

I get the same error while interacting with initially deployed instance too, Let me know if am missing something here ?

@EngrPips
Copy link

Did you connect the Remix to Metamask?

@sandeepV2
Copy link
Author

Nope i did not connect any wallet. Opened fresh tab with (Open in Remix) button.

@EngrPips
Copy link

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.

1 similar comment
@EngrPips
Copy link

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.

@sandeepV2
Copy link
Author

#1940 (comment)

I used the Cancun evm version as well, and yeah,

You did mention that it worked for Cancun evm too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants