Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Use ChainLink Feed Registry

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

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

contract PriceConsumer {
    FeedRegistryInterface internal registry;

    /**
     * Network: Ethereum Kovan
     * Feed Registry: 0xAa7F6f7f507457a1EE157fE97F6c7DB2BEec5cD0
     */
    constructor(address _registry) {
        registry = FeedRegistryInterface(_registry);
    }

    /**
     * Returns the ETH / USD price
     */
    function getEthUsdPrice() public view returns (int) {
        (
            uint80 roundID,
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = registry.latestRoundData(Denominations.ETH, Denominations.USD);
        return price;
    }

    /**
     * Returns the latest price
     */
    function getPrice(address base, address quote) public view returns (int) {
        (
            uint80 roundID, 
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = registry.latestRoundData(base, quote);
        return price;
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: reference to javascript array 
Javascript :: add google maps nuxt js 
Javascript :: detect paste in textarea 
Javascript :: how to connect two model in mongoose 
Javascript :: Set objects Relation with Strings javascript 
Javascript :: .catch() in promise will aslo return a promise 
Javascript :: react clikc with ref 
Javascript :: python to javascript code converter 
Javascript :: include nested childs 
Javascript :: cara install parrot os di virtualbox 
Javascript :: EventEmitter to emit a custom event 
Javascript :: javascript const memory 
Javascript :: Node-Red Custom UI 
Javascript :: add link in react table 
Javascript :: javascript find in array cannot read property of undefined 
Javascript :: dict equivalent js 
Javascript :: how to create dynamic radio button in jquery 
Javascript :: react-spring 
Javascript :: scroll to bottom of page javascript 
Javascript :: Passing arrays to functions with the spread operator 
Javascript :: get user id from username discord 
Javascript :: react axios request data objest from online json with table element 
Javascript :: how to cut and paste an element in vanilla javascript 
Javascript :: convert snake case to camelcase javascript recursive 
Javascript :: How to set canvas height and width dynamically 
Javascript :: onclick add and remove class using jquery 
Javascript :: regex from 5 to 30 1 number 1 lower case and 1 upper case letter 
Javascript :: how to create session cookie in node js 
Javascript :: pass function name as string javascript 
Javascript :: Uncaught TypeError: document.getElementById(...).exitFullscreen is not a function 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =