What you’ll be doing in this guide
This tutorial shows you how to:- Integrate API3’s data feeds into your smart contract on Sei
- Get real-time price data for the SEI token from API3’s proxy contract
- Understand the structure of API3’s reader proxy interface
- Deploy and test your integration on Sei
Prerequisites
Before you start this tutorial, make sure that you have:Technical requirements
- Solidity knowledge: A basic understanding of smart contract development in Solidity
- Development environment: Remix IDE, Hardhat, or a similar Solidity development setup
- Sei network access: An RPC endpoint and access to Sei Mainnet
Required dependencies
- OpenZeppelin Contracts library (
@openzeppelin/contracts) - API3 Contracts library (
@api3/contracts)
Install
Sei network configuration
Make sure that your development environment is configured for Sei:- Mainnet RPC:
https://evm-rpc.sei-apis.com - Chain ID: 1329 (Sei Mainnet)
Contract code
This complete smart contract reads SEI price data from API3:Contract breakdown
Main components:- Proxy address: The contract stores the address of the API3 proxy that supplies SEI price data
- Data validation: The contract validates that price values are positive and that timestamps are recent
- IApi3ReaderProxy interface: This interface has the
read()function, which fetches price data
readDataFeed() function:
- Returns
int224 value: The SEI price (likely in USD with 18 decimal places) - Returns
uint256 timestamp: When the price was last updated - Checks that the data is fresh (within 1 day)
- Checks that the price is positive
Proxy address
This tutorial uses the API3 proxy at this address on Sei:0x09c6e594DE2EB633902f00B87A43b27F80a31a60
This proxy supplies real-time SEI/USD price data from API3’s decentralized oracle network.
How to test
1. Deploy the contract
Using Remix IDE:- Open Remix IDE
- Create a new file named
DataFeedReaderExample.sol - Paste the contract code from above
- Compile the contract with the Solidity compiler (version ^0.8.0)
- Deploy with this constructor parameter:
0x09c6e594DE2EB633902f00B87A43b27F80a31a60
2. Read price data
After you deploy the contract, call thereadDataFeed() function to get the current SEI price:
value: The SEI price in USD (with 18 decimals, for example300000000000000000= $0.3)timestamp: Unix timestamp of the last price update