Documentation Index
Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
Use this file to discover all available pages before exploring further.
Please view the third-party content disclaimer here.
Supra provides oracle price feeds for EVM-compatible chains including Polygon. Two integration patterns are available: Pull Oracle (fetch proof data off-chain, then submit onchain) and Push Oracle (read S-Values directly from an onchain contract).
Pull Oracle integration
The Pull Oracle fetches proof data from Supra’s gRPC server and passes it to your smart contract via a JavaScript client.
Prerequisites
- Node.js installed.
- A deployed smart contract that accepts Supra proof data.
Install dependencies
Clone the Supra repository or download the source, then run:
Configure main.js
Set the following parameters before running the client.
gRPC server address:
| Environment | Address |
|---|
| Mainnet | mainnet-dora-2.supra.com:443 |
| Testnet | testnet-dora-2.supra.com:443 |
REST server address:
| Environment | URL |
|---|
| Mainnet | https://rpc-mainnet-dora-2.supra.com |
| Testnet | https://rpc-testnet-dora-2.supra.com |
Pair indexes (example):
const pairIndexes = [0, 21, 61, 49];
Chain type:
RPC URL:
const web3 = new Web3(new Web3.providers.HttpProvider('<RPC URL>'));
Update the ABI path:
const contractAbi = require("../resources/abi.json");
Set the contract address:
const contractAddress = '<CONTRACT ADDRESS>';
Update the function call to match your contract:
const txData = contract.methods.GetPairPrice(hex, 0).encodeABI();
Estimate gas:
const gasEstimate = await contract.methods.GetPairPrice(hex, 0).estimateGas({ from: "<WALLET ADDRESS>" });
Build the transaction:
const transactionObject = {
from: "<WALLET ADDRESS>",
to: contractAddress,
data: txData,
gas: gasEstimate,
gasPrice: await web3.eth.getGasPrice()
};
Sign with your private key:
const signedTransaction = await web3.eth.accounts.signTransaction(transactionObject, "<PRIVATE KEY>");
Run the application
This retrieves proof data from Supra’s servers and submits it to your contract using the configured parameters.
Push Oracle integration
The Push Oracle exposes real-time data feeds (S-Values) directly onchain through a Solidity interface.
Step 1: Define the S-Value interface
Add this interface to your contract:
pragma solidity 0.8.19;
interface ISupraSValueFeed {
struct priceFeed {
uint256 round;
uint256 decimals;
uint256 time;
uint256 price;
}
struct derivedData {
int256 roundDifference;
uint256 derivedPrice;
uint256 decimals;
}
function getSvalue(uint256 _pairIndex) external view returns (priceFeed memory);
function getSvalues(uint256[] memory _pairIndexes) external view returns (priceFeed[] memory);
function getDerivedSvalue(uint256 pair_id_1, uint256 pair_id_2, uint256 operation)
external
view
returns (derivedData memory);
function getTimestamp(uint256 _tradingPair) external view returns (uint256);
}
Step 2: Initialize the feed address
Set the S-Value feed contract in your constructor. Replace the address below with the correct network-specific Supra contract address.
contract ISupraSValueFeedExample {
ISupraSValueFeed internal sValueFeed;
constructor() {
sValueFeed = ISupraSValueFeed(0xE92D276bBE234869Ecc9b85101F423c6bD26654A);
}
}
Step 3: Read S-Value data
Use these functions to fetch single or multiple S-Values, or derive new data pairs:
function getPrice(uint256 _priceIndex)
external
view
returns (ISupraSValueFeed.priceFeed memory)
{
return sValueFeed.getSvalue(_priceIndex);
}
function getPriceForMultiplePair(uint256[] memory _pairIndexes)
external
view
returns (ISupraSValueFeed.priceFeed[] memory)
{
return sValueFeed.getSvalues(_pairIndexes);
}
function getDerivedValueOfPair(uint256 pair_id_1, uint256 pair_id_2, uint256 operation)
external
view
returns (ISupraSValueFeed.derivedData memory)
{
return sValueFeed.getDerivedSvalue(pair_id_1, pair_id_2, operation);
}
Recommended: support feed address updates
Add an owner-controlled function to update the Supra feed contract address for future upgrades:
function updateSupraSvalueFeed(ISupraSValueFeed _newSValueFeed)
external
onlyOwner
{
sValueFeed = _newSValueFeed;
}