SaucerSwap
AppMerchBlog
Developer
Developer
  • Developer Resources
  • REST API
    • Stats
    • Farms
    • Tokens
    • Pools (V1)
    • Pools and Positions (V2)
  • SaucerSwap V1
    • Swap Operations
      • Swap Quote
      • Swap HBAR for Tokens
      • Swap Tokens for Tokens
      • Swap Tokens for HBAR
      • Track Swap Events
    • Liquidity Operations
      • Fetch All Pools
      • Check if a Pool Exists
      • Pool Creation Fee
      • Create a New Pool
      • Get Pool Reserves
      • Track Pool Updates
      • Adding Liquidity
      • Removing Liquidity
  • SaucerSwap V2
    • Swap Operations
      • Swap Quote
      • Swap HBAR for Tokens
      • Swap Tokens for Tokens
      • Swap Tokens for HBAR
      • Track Swap Events
    • Liquidity Operations
      • Fetch all Pools
      • Check if a Pool Exists
      • Fetch Pool Token Ratio
      • Liquidity Position Fee
      • New Liquidity Position
      • Increasing Liquidity
      • Get User Positions
      • Claiming Fees
      • Decreasing Liquidity
  • Staking Operations
    • Single-Sided Staking
    • Yield Farming
  • WHBAR
    • Wrap HBAR for WHBAR
    • Unwrap WHBAR for HBAR
  • Contract Deployments
Powered by GitBook
On this page
  • Get the Existing Liquidity Pool if it Exists
  • Code Overview
  1. SaucerSwap V1
  2. Liquidity Operations

Check if a Pool Exists

Check if the liquidity pool for a pair of HTS tokens exists on-chain.

PreviousFetch All PoolsNextPool Creation Fee

Last updated 1 year ago

When adding a new or existing liquidity pool, the initial step is typically to verify if the liquidity pool already exists before determining the next course of action. The factory contract provides a method to retrieve the pool address, if it exists, as shown below.

Checking if the liquidity pool exists using SaucerSwap's REST API is also a suitable alternative. For more information, see


Get the Existing Liquidity Pool if it Exists

⛽ No gas cost

Get the existing liquidity pool's CREATE2 EVM address if it exists. If the pool does not exist on-chain, a zero address will be returned.

Function name: getPair

Parameter Name
Description

address tokenA

EVM address of the first token

address tokenB

EVM address of the second token

Solidity Interface
//IUniswapV2Factory.sol

function getPair(
  address tokenA,
  address tokenB
) external view returns (address pair);

When working with HBAR, use the wrapped HBAR token ID () for either tokenA or tokenB.

The ordering of tokens for tokenA and tokenB does not matter.

Code Overview

Resources:

import * as ethers from 'ethers'; //V6

//Set one of Hedera's JSON RPC Relay as the provider
const provider = new ethers.JsonRpcProvider(hederaJsonRelayUrl, '', {
  batchMaxCount: 1, //workaround for V6
});

//load ABI data containing the Factory's getPair function
const interfaces = new ethers.Interface(abi);

const factoryContract = new ethers.Contract(factoryEvmAddress, interfaces.fragments, provider);
const result = await factoryContract.getPair(tokenA, tokenB); //(tokenB, tokenA) will give same result
const poolEvmAddress = result; //address pool
Get V1 liquidity pools
WHBAR
Ethers.js docs (v6)
Hedera JSON RPC Relay