Indicadores de precios en el Blockchain

Ahmed Castro - Jul 1 '21 - - Dev Community

Con ayuda del oráculo de Chainlink podemos acceder a precios de muchas monedas desde solidity. La buena noticia es que es totalmente gratis.

Para hacerlo solo asegurate de inializar el priceFeed con el address del par de precios deseas. Puedes acceder al listado de addresses vista esta página.

pragma solidity 0.8.5;

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

contract PriceConsumerV3 {

    AggregatorV3Interface internal priceFeed;

    constructor() public {
        priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e); // Rinkeby ETH/USD price
    }

    function getThePrice() public view returns (int) {
        (
            uint80 roundID, 
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
        return price;
    }
}
Enter fullscreen mode Exit fullscreen mode

Documentación oficial

Gracias por ver este tutorial!

Sígueme en dev.to y en Youtube para todo lo relacionado al desarrollo en Blockchain en Español.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .