The LayerOneOracle API is used to get the current exchange rates in USD of ETH. This rate us fed by the Chainlink price feeds. Please supply a layer 1 web3 instance obtaining an LayerOneOracle API from `getSDK()

Example

import { getSDK } from "@cardstack/cardpay-sdk";
let web3 = new Web3(myProvider); // Layer 1 web3 instance
let layerOneOracle = await getSDK('LayerOneOracle', web3);

Hierarchy

  • LayerOneOracle

Implements

Constructors

Properties

layer1Web3: default

Methods

  • This call will return the USD value for the specified amount of ETH. This API requires that the amount be specified in wei (1018 wei = 1 token) as a string, and will return a floating point value in units of USD. You can easily convert an ETH value to wei by using the Web3.utils.toWei() function.

    Example

    let layerOneOracle = await getSDK('LayerOneOracle', web3);
    let usdPrice = await exchangelayerOneOracleRate.ethToUsd(amountInWei);
    console.log(`USD value: $${usdPrice.toFixed(2)} USD`);

    Parameters

    • ethAmount: string

    Returns Promise<number>

  • This returns a function that converts an amount of ETH in wei to USD. The returned function accepts a string that represents an amount in wei and returns a number that represents the USD value of that amount of ETH.

    Example

    let layerOneOracle = await getSDK('LayerOneOracle', web3);
    let converter = await layerOneOracle.getEthToUsdConverter();
    console.log(`USD value: $${converter(amountInWei)} USD`);

    Returns Promise<((ethAmountInWei: string) => number)>

Generated using TypeDoc