LOGBOOK

HELP

Quiz Entry - updated: 2026.07.30

How do you read the ETH/USD price with Chainlink's AggregatorV3Interface, and why must you handle decimals?

You point an AggregatorV3Interface at the feed's address and call latestRoundData(); the price comes back as an int scaled by the feed's decimals (typically 8), so you multiply to match wei's 18 decimals.

AggregatorV3Interface priceFeed = AggregatorV3Interface(0x...); // feed address
(, int256 price, , , ) = priceFeed.latestRoundData();
// price of ETH/USD, but with 8 decimals, e.g. 300000000000 for 3000.00000000
return uint256(price) * 1e10;   // scale 8 -> 18 decimals

latestRoundData() returns several values; the one you want is price. Two subtleties:

  • Decimals — Solidity has no fractional numbers, so the feed encodes the price as an integer with a fixed number of decimal places (ETH/USD uses 8). msg.value uses 18. To compare or multiply them you scale the price up by 1e10 so both use 18 decimals. The feed's decimals() function tells you the exact count.
  • Signed typeprice is int256 (feeds could in principle be negative), so you typecast it to uint256 with uint256(price).

Go deeper:

From Quiz: IOTHACK / Smart Contracts & the Remix IDE | Updated: Jul 30, 2026