0

How to get the token Market price value in the solidity smart contract. I want to fetch the token price in the same contract like there is A token and I want the token Market price value in the same A token.

I have used the chain link in the contract like this but I want the price of my erc20 the A token Market price value

dataFeed = AggregatorV3Interface(
            0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43
        );   
                                                                                                                                      function getLatestPrice() public view returns (int) {
    (
        uint80 roundID, 
        int price,
        uint startedAt,
        uint timeStamp,
        uint80 answeredInRound
    ) = dataFeed.latestRoundData();
    return price;
}

1 Answer 1

0

You can use Chainlink oracles for many of the tokens, see: https://data.chain.link

If there is no oracle available, you could figure out the price of the token from a liquidity pool (like Uniswap V2/V3 pool).

In both cases (especially in the latter one) you can't fully trust the price, as it could be manipulated and should add additional checks to ensure the price is valid.

Chainlink oracles are pretty reliable though, so for many applications these should be OK to use as is.

1
  • I have used the chain link in the contract like this but I want the price of my erc20 token dataFeed = AggregatorV3Interface( 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43 ); function getLatestPrice() public view returns (int) { ( uint80 roundID, int price, uint startedAt, uint timeStamp, uint80 answeredInRound ) = dataFeed.latestRoundData(); return price; } Sep 29, 2023 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.