How to Use IFA Oracle Price Feed in EVM Contracts

This guide explains how to integrate IFA Oracle price feeds into your EVM contracts for accessing real-time stablecoin and asset price data. IFA Oracle provides decentralized price feeds specialized for stablecoins and other assets with high precision calculations.


Install IFA Price Feed Interface

IFA Oracle provides a Solidity interface package to interact with the deployed price feed contracts.

Truffle/Hardhat

If you are using Truffle or Hardhat, simply install the NPM package:

npm install ifapricefeed-interface

Foundary

If you are using Foundry, you will need to create an NPM project if you don't already have one. From the root directory of your project, run:

npm init -y
npm install ifapricefeed-interface

Then add the following line to your remappings.txt file:

ifapricefeed-interface/=node_modules/ifapricefeed-interface

Contract Addresses and Asset Registry

Write Contract Code

The code snippet below provides a general template for integrating IFA Oracle price feeds:

The code snippet above demonstrates the following key steps:

  1. Instantiate the IIfaPriceFeed interface from the Solidity interface package using the price feeds contract address.

  2. Select the Asset IDs for the assets you want to fetch prices for. Asset IDs are generated by hashing the asset symbol.

  3. Call IIfaPriceFeed.getAssetInfo to read individual asset price information.

  4. Call IIfaPriceFeed.getPairbyId to calculate exchange rates between two assets.

  5. Handle decimal precision correctly - derived pair prices have 30 decimal places for maximum precision.


Key Concepts

Assets

An asset represents a token's price with respect to USD (e.g., CNGN/USD, BTC/USD). Each asset is identified by a unique hash of its symbol.

Pairs

A pair represents the exchange rate between two assets (e.g., CNGN/BTC). Pairs can be calculated in both forward and backward directions.

Precision

  • Asset prices use their native decimal precision (stored as negative values, e.g., -18 for 18 decimals)

  • Derived pair prices are always scaled by 10^30 for maximum precision


Function Examples

1. Get Single Asset Information

2. Get Multiple Assets Information

3. Get Single Pair Exchange Rate

4. Get Multiple Pairs (Forward Direction)

5. Get Multiple Pairs (Backward Direction)

6. Get Multiple Pairs with Custom Directions


Example of Real-World Use Cases

1. Stablecoin Swap Contract

2. Price Validation Contract


Data Structures

PriceFeed

DerviedPair

PairDirection


Error Handling

The IFA Price Feed system includes comprehensive error handling:


Best Practices

  1. Always check asset existence before using price data

  2. Validate price freshness by checking lastUpdateTime

  3. Handle the 10^30 scaling correctly for derived pairs

  4. Use batch functions for multiple assets to save gas

  5. Implement proper error handling for failed price lookups


Common Asset Symbols

Replace the placeholder Asset IDs (0x0000..., 0x1111..., etc.) in the examples above with actual Asset IDs from our supported assets:

  • CNGN - Nigerian Naira stablecoin

  • USDT - USD Stablecoin (by Tether)

  • USDC - USD Stablecoin (by circle)

  • EURC - Euro Stablecoin

  • BTC - Bitcoin

  • ETH - Ethereum

  • And many more...

For the complete list of supported assets and their corresponding Asset IDs, see our Asset Registry.


Additional Resources


Support

For technical support and integration assistance, please refer to the IFA Labs documentation or contact the development team here

Last updated