Contract Reads

getContract()

Get a mapping of promise of all readable values of a contract in a specific chain.

Signature

type Chain = "eth" | "bsc" | "polygon"
getContract(chain: Chain, address: string): Promise<Record<string, Promise<() => unknown>>>

Example

async function process({ dataSource }) {
    const UNISWAP_ETH_USDC_LP = "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640";
    const contract = await dataSource.get("contract").getContract("eth", UNISWAP_ETH_USDC_LP);
    /**
     * {
     *   factory: Promise<string>;
     *   fee: Promise<BigNumber>;
     *   ...
     *   token0: Promise<string>;
     *   token1: Promise<string>;
     * }
     */
})

getContract().readFunction()

Call a contract read asynchronously from a contract.

If the contract is verified in a block explorer, you can find all available contract reads on the contract on the platform.

As in our example, you can see all read methods on https://etherscan.io/address/0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640#readContract

Signature

type Chain = "eth" | "bsc" | "polygon"
getContract(chain: Chain, address: string): Promise<Record<string, Promise<() => unknown>>>

Example

async function process({ dataSource }) {
    const UNISWAP_ETH_USDC_LP = "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640";
    const contract = await dataSource.get("contract").getContract("eth", UNISWAP_ETH_USDC_LP);
    const liquidity = await contract.liquidity();
    // 37390839582564985275
    const observation = await contract.observation(1);
    /** {
     *   blockTimestamp:  1689656759
     *   tickCumulative:  13856267136263
     *   secondsPerLiquidityCumulativeX128:  151724863035695328813484017762
     *   initialized:  true
     * }
     */
})

Last updated