> For a complete index of Agora Finance documentation, fetch https://docs.agora.finance/llms.txt

# Fetching Purchase Fees

> Query fee rates for a specific trading pair before executing a swap

> **Note**
>
> If you want to run this example, be sure that you have followed the steps [here](/instant-settlement/guides/quick-start#setting-up-a-viem-wallet-client) to configure your Wallet Client.

The [`AgoraStableSwapPair`](/instant-settlement/smart-contracts/pair-contract) contract stores the current purchase-fee rate :

* **`token0PurchaseFee`** – fee charged when buying **token0** (i.e., swapping *into* token0).
* **`token1PurchaseFee`** – fee charged when buying **token1**.

The returned rates are both using 18 decimal "fee precision" units.

## Pick a pair address

```tsx
// AUSD / CTK pair on Sepolia
const TESTNET_PAIR_AUSD_CTK = '0x1Aa8958Aa34cEC8096EF4381cb335effe977b0ae';
```

## Helper function to read the purchase fees

```tsx
/**
 * Returns raw purchase-fee rates (18-dec precision).
 */
async function getPairPurchaseFees(
  pair: `0x${string}`,
): Promise<{ token0PurchaseFee: bigint; token1PurchaseFee: bigint }> {
  const token0PurchaseFee = await client.readContract({
    address: pair,
    abi: instantSettlementAbi,
    functionName: "token0PurchaseFee",
    args: [],
  });

  const token1PurchaseFee = await client.readContract({
    address: pair,
    abi: instantSettlementAbi,
    functionName: "token1PurchaseFee",
    args: [],
  });

  return { token0PurchaseFee, token1PurchaseFee };
}
```

## Example use of the helper function

```tsx
(async () => {
  const { token0PurchaseFee, token1PurchaseFee } = await getPairPurchaseFees(
    TESTNET_PAIR_AUSD_CTK,
  );

  console.log("Purchase fee (token0 → token1):", token0PurchaseFee);
  console.log("Purchase fee (token1 → token0):", token1PurchaseFee);
})();
```

### Returned Data

```tsx
Purchase fee (token0 → token1): 100000000000000n   // 0.01% (1 bps)
Purchase fee (token1 → token0): 200000000000000n   // 0.02% (2 bps)
```

This is the value stored by the contract. In order to convert these units to human readable values, we'll need to divide the output by the [`ERC20`](https://eips.ethereum.org/EIPS/eip-20) token decimals.