๐ŸงฉExamples

Typescript

import axios from 'axios';
import  { ethers } from 'ethers';
const abi = [
"updatePriceFeeds((uint256,bytes,bytes32[])[],(uint256,uint256,bytes32,bytes32,uint256),uint256[2],bytes)"
]
const API_BASE_URL = 'https://api.eoracle.network/api/v1/get_rate';
const EORACLE_CHAINS = {
    HOLESKY: {
        ADDRESS: '0x723BD409703EF60d6fB9F8d986eb90099A170fd0',
        RPC_URL: 'https://some.holesky.rpc',
    },
}
const SYMBOL = 'btc'; // replace with your desired symbol

interface LeafInput {
    leafIndex: BigInt;
    unhashedLeaf: string;
    proof: string;
}

interface Checkpoint {
    epoch:BigInt:
    blockNumber:BigInt;
    eventRoot:string;
    blockHash:string;
    blockRound:BigInt;
}
interface IProvableFeed{
    leafInput: LeafInput;
    checkpoint:Checkpoint;
    signature:BigInt[];
    bitmap:string; 
    
}
async function fetchFeed(symbol: string): Promise<IProvableFeed> {
    const response = await axios.get(`${API_BASE_URL}?symbol=${symbol}`, { 
        auth: {
            username: 'your_api_key', // replace with your actual authentication token
            password: ''
        }
    });
    const quote : IProvableFeed = {
        symbol: response.data.symbol,
        rate: response.data.rate, 
        timestamp: response.data.timestamp, 
        leafInput : response.data.leafinput, 
        checkpoint : reponse.data.checkpoint
        signature: response.data.signature,
        bitmap: response.data.bitmap
    }
    return quote;
}

async function main() {
    const provider = new ethers.JsonRpcProvider(EORACLE_CHAINS.HOLESKY.RPC_URL); // replace `HOLESKY` with your network 
    const consumer = new ethers.Wallet(
        '0xYOUR_PRIVATE_KEY',
        provider
    );
    const contract = new ethers.Contract(EORACLE_CHAINS.HOLESKY.ADDRESS, contractAbi, consumer); // replace `HOLESKY` with your network
    const feed = await fetchFeed(SYMBOL);    
    console.log(`received symbol for ${feed.symbol}: ${feed.rate} at timestamp ${feed.timestamp}`);
    try {
        const tx = await contract.updatePriceFeeds(feed);
        console.log(`verifying price for symbol ${SYMBOL}. please wait...`)
        await tx.wait();
        const rate = await contract.getLatestFeed(SYMBOL);
        console.log(`verified price of ${SYMBOL} is ${rate[0]} with timestamp ${rate[1]}`);
    } catch (error) {
        console.error('Error updating feeds:', error);
    }
}

main()
    .then(() => process.exit(0))
    .catch(error => {
        console.error(error);
        process.exit(1);
    });

Last updated