2

Is there a way to get all the liquidity of a token? Also locked and burned liquidities, actually my aim is to build something similar to token sniffer, thanks for your help

1 Answer 1

3

You have to use the factory abi of all dexes to get liquidity for the mostly used tokens from front end. Eg. the factory address of pancakeswap is 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73. The abi of pancakefatory have a function named getPair(address token1, address token2). Then in front end with web3 or etherjs you will initialize factory contract.

Here is the simple example for finding single pair:

const [pair, setPair] = useState("")
const token1;
const token2;
const pancakeFatory = new ethers.contract(factoryContract, abi, provider)
const setPair = async () => {
  const pairAvailable = await pancakeFactory.getPair(token1, token2);
  setPair(pairAvailable)
}

If you have multiple factories and multiple tokens to check like usdt, bnb, eth, btc etc then you have to utilize nested loop and if pair returned is 0 address then the pair is not available and pair returned is not a zero address then pair is available.

1
  • Thank you very much, your answer was really great, now is there a function that I can get all the pairs and find out from it if my token is zero or token one is the token I am checking and filter it? And is there a way I can calculate the locked and burned liquidity?
    – Mehran Ra
    Mar 3, 2023 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.