I'm trying to get the pairaddress and pairname of a given pancakeswap token with web3. I didn't found any solution yet. Is there a good example how to get it and which abi and contract address should i use in my eth.contract method?

  • Thank you for your answer @YongjianP. but i was actually asking for the opposite way... finde the pair address of a given token and not vice versa. There are a lot of examplet how to find the token out of the factory addres but not the way around... :/ Sep 10 at 18:19
  • To get the token pair address you need two tokens and call getPair on the factory contract. You could get the factory address from the router calling factory(). See pancakeswap documentation for the details docs.pancakeswap.finance/code/smart-contracts/….
    – Ismael
    Sep 14 at 3:57
  • Thank you so much @Ismael that helped me a lot! But what if i don't know the second token... i mean what if i only know token0? That's the point. I know, most of the time the second token in pancakeswap is WBNB, but sometimes it can be anything... it can be BUSD or USDT... you know what i mean? Sep 14 at 9:23
  • @AntonioImenes A PancakePair requires two tokens, there's no pair for a single token. It is possible with allPairsLength and allPairs(uint) to interate existing pairs. That should be done off-chain to save gas.
    – Ismael
    Sep 14 at 19:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.