> ## 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.

# Supra

> How to integrate Supra Pull Oracle and Push Oracle into a Polygon smart contract or JavaScript application.

<Note title="Content disclaimer">
  Please view the third-party content disclaimer [here](https://github.com/0xPolygon/polygon-docs/blob/main/CONTENT_DISCLAIMER.md).
</Note>

[Supra](https://supra.com/) 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:

```bash theme={null}
npm install
```

### 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):

```javascript theme={null}
const pairIndexes = [0, 21, 61, 49];
```

**Chain type:**

```javascript theme={null}
const chainType = 'evm';
```

**RPC URL:**

```javascript theme={null}
const web3 = new Web3(new Web3.providers.HttpProvider('<RPC URL>'));
```

### Configure contract interaction

Update the ABI path:

```javascript theme={null}
const contractAbi = require("../resources/abi.json");
```

Set the contract address:

```javascript theme={null}
const contractAddress = '<CONTRACT ADDRESS>';
```

Update the function call to match your contract:

```javascript theme={null}
const txData = contract.methods.GetPairPrice(hex, 0).encodeABI();
```

Estimate gas:

```bash theme={null}
const gasEstimate = await contract.methods.GetPairPrice(hex, 0).estimateGas({ from: "<WALLET ADDRESS>" });
```

Build the transaction:

```bash theme={null}
const transactionObject = {
  from: "<WALLET ADDRESS>",
  to: contractAddress,
  data: txData,
  gas: gasEstimate,
  gasPrice: await web3.eth.getGasPrice()
};
```

Sign with your private key:

```bash theme={null}
const signedTransaction = await web3.eth.accounts.signTransaction(transactionObject, "<PRIVATE KEY>");
```

### Run the application

```bash theme={null}
node main.js
```

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:

```solidity theme={null}
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.

```solidity theme={null}
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:

```solidity theme={null}
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:

```solidity theme={null}
function updateSupraSvalueFeed(ISupraSValueFeed _newSValueFeed)
    external
    onlyOwner
{
    sValueFeed = _newSValueFeed;
}
```
