Skip to main content
Please view the third-party content disclaimer here.
Chainlink lets your contracts access external data through a decentralized oracle network. The most common use case on Polygon is reading price feeds directly from Chainlink Data Feeds.

Prerequisites

  • A Solidity contract deployed or ready to deploy on Polygon PoS or Amoy testnet.
  • The Chainlink AggregatorV3Interface imported from @chainlink/contracts.

Read a price feed

The contract below reads the latest POL/USD price on the Amoy testnet. To use a different price pair, replace the feed address with any address from the Chainlink Polygon feed list.
pragma solidity ^0.8.26;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

contract PriceConsumerV3 {
    AggregatorV3Interface internal priceFeed;

    /**
     * Network: Amoy Testnet
     * Aggregator: POL/USD
     * Address: 0x001382149eBa3441043c1c66972b4772963f5D43
     */
    constructor() public {
        priceFeed = AggregatorV3Interface(0x001382149eBa3441043c1c66972b4772963f5D43);
    }

    /**
     * Returns the latest price
     */
    function getLatestPrice() public view returns (int) {
        (
            uint80 roundID,
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
        return price;
    }
}

Next steps