API3 is a decentralized oracle network that provides real-time data feeds to smart contracts. Unlike traditional oracles that rely on third-party intermediaries, API3 connects APIs directly to the blockchain through first-party oracles operated by the API providers themselves. This approach reduces trust assumptions and potential points of failure.Documentation Index
Fetch the complete documentation index at: https://seilabs.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
What You’ll Be Doing in This Guide
In this tutorial, you’ll learn how to:- Integrate API3’s data feeds into your smart contract on the SEI network
- Retrieve real-time SEI token price data using API3’s proxy contract
- Understand the structure of API3’s reader proxy interface
- Deploy and test your integration on SEI
Prerequisites
Before starting this tutorial, ensure you have:Technical Requirements
- Solidity Knowledge: Basic understanding of Solidity smart contract development
- Development Environment: Remix IDE, Hardhat, or similar Solidity development setup
- SEI Network Access: RPC endpoint and mainnet access for SEI
Required Dependencies
- OpenZeppelin Contracts library (
@openzeppelin/contracts) - API3 Contracts library (
@api3/contracts)
Install
SEI Network Configuration
Make sure your development environment is configured for SEI:- Mainnet RPC:
https://evm-rpc.sei-apis.com - Chain ID: 1329 (mainnet)
Contract Code
Here’s the complete smart contract code for integrating with API3 to read SEI price data:Contract Breakdown
Key Components:- Proxy Address: The contract stores the API3 proxy address that provides SEI price data
- Data Validation: The contract validates that price values are positive and timestamps are recent
- IApi3ReaderProxy Interface: This interface provides the
read()function to fetch 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 - Validates data freshness (within 1 day)
- Ensures price is positive
Proxy Address
For this tutorial, we’ll be using the following API3 proxy address on SEI:0x09c6e594DE2EB633902f00B87A43b27F80a31a60
This proxy provides 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 called
DataFeedReaderExample.sol - Paste the contract code above
- Compile the contract using Solidity compiler ^0.8.0
- Deploy with constructor parameter:
0x09c6e594DE2EB633902f00B87A43b27F80a31a60
2. Read Price Data
After deployment, call thereadDataFeed() function to retrieve the current SEI price:
value: SEI price in USD (with 18 decimals, e.g.,3000000000000000= $0.3)timestamp: Unix timestamp of the last price update