Skip to content

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

Open
@sandeepV2

Description

@sandeepV2

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 ?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions