Skip to main content

Fetching Pair Reserves

Fetching live reserves is useful for knowing the liquidity on each side of the pair before you trade. The snippet below re-uses the wallet client you created in Quick Start, so no extra setup is needed.

  • If you are following our example using Avalanche Fuji, you can use the Address 0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF .
  • If you are trying to swap in a mainnet chain, you can check out Find all available Pairs

1. Pick a pair address

// AUSD / CTK pair on Avalanche Fuji Testnet
const TESTNET_PAIR_AUSD_CTK = '0x237591AaF2FCCb34464Ceae9EeA1eb6f375843AF';

In order to query the reserves from the contract, we'll call the methods reserve0 and reserve1

2. Helper to read raw reserves

/**
* Returns the raw on-chain reserves (no decimal conversion).
*/
async function getPairReserves(
pair: `0x${string}`,
): Promise<{ reserve0: bigint; reserve1: bigint }> {
const reserve0 = await client.readContract({
address: pair,
abi: stableSwapAbi,
functionName: "reserve0",
});

const reserve1 = await client.readContract({
address: pair,
abi: stableSwapAbi,
functionName: "reserve1",
});

return { reserve0, reserve1 };
}

3. Run the query

(async () => {
const { reserve0, reserve1 } = await getPairReserves(TESTNET_PAIR_AUSD_CTK);

console.log(`Reserves token0 (AUSD – 6 dec):`, reserve0);
console.log(`Reserves token1 (CTK – 18 dec):`, reserve1);
})();
Reserves token0 (AUSD6 dec): 1000000000000n
Reserves token1 (CTK18 dec): 1000000000000000000000000n

This is the value stored by the contract. In order to convert this units to human readable values, we'll need to divide the output by the ERC20 token decimals.