Get the latest price from a Chainlink price feed
Viem public client
Price feed contract address
Price feed result
const result = await getLatestPrice(client, PRICE_FEED_ADDRESSES['eip155:8453']['ETH/USD']);const priceUsd = Number(result.price) / Math.pow(10, result.decimals);console.log(`ETH price: $${priceUsd}`); Copy
const result = await getLatestPrice(client, PRICE_FEED_ADDRESSES['eip155:8453']['ETH/USD']);const priceUsd = Number(result.price) / Math.pow(10, result.decimals);console.log(`ETH price: $${priceUsd}`);
Get the latest price from a Chainlink price feed