Getting the reserves data for a liquidity pool using SaucerSwapโs REST API is also a suitable alternative. For more information, see Get liquidity pool reserves (V1). The pool metadata includes the reserve data.
To track updates to liquidity pool reserves in near real-time, see Track LP updates (V1).
import * as ethers from 'ethers'; //V6//Set one of Hedera's JSON RPC Relay as the providerconst provider = new ethers.JsonRpcProvider(hederaJsonRelayUrl, '', { batchMaxCount: 1, //workaround for V6});//load abi data containing Pair's getReserves() functionconst interfaces = new ethers.Interface(abi);const poolContract = new ethers.Contract(poolAddress, interfaces.fragments, provider);const result = await poolContract.getReserves();const reserve0 = result.reserve0; //in token's smallest unitconst reserve1 = result.reserve1; //in token's smallest unitconst block = result.blockTimestampLast;
import * as ethers from 'ethers'; //V6//Set one of Hedera's JSON RPC Relay as the providerconst provider = new ethers.JsonRpcProvider(hederaJsonRelayUrl, '', { batchMaxCount: 1, //workaround for V6});//load abi data containing Pair's getReserves() functionconst interfaces = new ethers.Interface(abi);const poolContract = new ethers.Contract(poolAddress, interfaces.fragments, provider);const result = await poolContract.getReserves();const reserve0 = result.reserve0; //in token's smallest unitconst reserve1 = result.reserve1; //in token's smallest unitconst block = result.blockTimestampLast;