Price Feed Tutorial

In this guide, we will explore the process of leveraging Nerif Network to automate a price feed.

The idea is to leverage smart contract functions and the capabilities of the Nerif Network to automate the process of monitoring and updating the ETH/USDT pair price in real-time, ensuring accurate and timely information within the smart contract.

Thus, our primary goal is to build a workflow that will be checking the price of the ETH/USDT pair and update its value within a smart contract accordingly.

To ensure a seamless flow of checking the price and updating its value within a smart contract, Nerif Network will be calling 2 functions from the below Price Feed smart contract:

  1. function priceChanged checking if the price of the ETH/USDT pair has changed

  2. function updatePrice to update the price of the ETH/USDT pair.

contract PriceFeed {
    uint256 public price;

    event PriceChanged(uint256 newPrice);

    function priceChanged(uint256 _price) external view returns (bool changed) {
        return price != _price;
    }

    function updatePrice(uint256 _price) external {
        price = _price;

        emit PriceChanged(_price);
    }
}

Last updated