---
# System prepended metadata

title: API3 - Chainlink adapter (getRoundData)

---

# API3 - Chainlink adapter (getRoundData)

## Chainlink Aggregators

```
function latestRound() external view returns (uint256 roundId)

function latestRoundData() external view
    returns (
        uint80 roundId,
        int256 answer,
        uint256 startedAt,
        uint256 updatedAt,
        uint80 answeredInRound
    )
    
function getRoundData(uint80 _roundId) external view 
    returns (
        uint80 roundId, 
        int256 answer, 
        uint256 startedAt, 
        uint256 updatedAt, 
        uint80 answeredInRound
    )
```

## Chainlink Adapter Contract

Deploy the following adapter contract with the approriate proxy address as seen on the [API3 market](https://market.api3.org/dapis) (For example the proxy address for ETH/USD is `0x26690F9f17FdC26D419371315bc17950a0FC90eD` on polygon mumbai):

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "@api3/contracts/v0.8/interfaces/IProxy.sol";

contract Api3AggregatorAdaptor {  

   // Updating the proxy address is a security-critical action which is why
   // we have made it immutable.
   address public immutable proxy;

   constructor(address _proxy) {
       proxy = _proxy;
   }
   
   function latestRoundData() external view
       returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        ) {
          (answer,updatedAt) = readDataFeed();
          startedAt = updatedAt;
          roundId = 2;
          answeredInRound = 2;
    }
    
   function latestRound() external view returns (uint256 roundId) {
       roundId = 2;
   }
    
   function getRoundData(uint80 _roundId) external view
       returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        ) {
          (answer,updatedAt) = readDataFeed();
          startedAt = updatedAt;
          roundId = 2;
          answeredInRound = 2;
    }

   function latestAnswer() external view returns (int256 value) {
       (value, ) = readDataFeed();
   }

   function latestTimestamp() external view returns (uint256 timestamp) {
       ( , timestamp) = readDataFeed();
   }
   
   function decimals() external view returns (uint8) {
       return 18;
   }
   
   function version() external view returns(uint256){
       return 4;
    }

   function readDataFeed()
       internal
       view
       returns (int224 value, uint256 timestamp)
   {
       (value, timestamp) = IProxy(proxy).read();
       // If you have any assumptions about `value` and `timestamp`, make sure
       // to validate them right after reading from the proxy. For example,
       // if the value you are reading is the spot price of an asset, you may
       // want to reject non-positive values...
       // require(value > 0, "Value not positive");
       // ...and if the data feed is being updated with a one day-heartbeat
       // interval, you may want to check for that.
       // require(
       //     timestamp + 1 days > block.timestamp,
       //     "Timestamp older than one day"
       // );
       // Try to be strict about validations, but be wary of:
       // (1) Overly strict validation that may invalidate valid values
       // (2) Mutable validation parameters that are controlled by a trusted
       // party (eliminates the trust-minimization guarantees of first-party
       // oracles)
       // (3) Validation parameters that need to be tuned according to
       // external conditions (if these are forgotten to be handled, it will
       // result in (1), look up the Venus Protocol exploit related to LUNA)

       // After validation, you can implement your contract logic here.
   }       

   function getTokenType() external pure returns (uint256) {
       return 1;
   }    
}
```

Once the adapter is deployed it can be be called via the ChainlinkInterface to retrieve the oracle values.

Please checkout the [API3 documentation](https://docs.api3.org/) on more information about dAPIs and the API3 market.