4

I am studying all listed pairs on Pancakeswap. I get the pair address from

PCS_FACTORY_ADDRESS="0xca143ce32fe78f1f7019d7d551a6402fc5350c73"
PCS_FACTORY_ADDRESS = Web3.toChecksumAddress(PCS_FACTORY_ADDRESS.lower() )
PCS_FACTORY_CONTRACT = w3.eth.contract(address=PCS_FACTORY_ADDRESS, abi=UNISWAP_FACTORY_ABI)
pair_contract = PCS_FACTORY_CONTRACT.functions.allPairs(n).call()

with n cycling from 0 to the current number of listed pairs. This works fine. When I have a pair address, how can I determine the underlying pair?

For example, for RAZOR the pair address is: 0x65d83d57c52d10e233bd4fed21fb9184ce00e861. Using

contract = w3.eth.contract(address=Web3.toChecksumAddress(pair_contract) , abi=PAIRS_ABI)
symbol = contract.functions.name().call()

I only get the name of the LP - Tokens (Pancake LPs). What I want to have is the address of the token itelf (for Razor it would be 0x50de6856358cc35f3a9a57eaaa34bd4cb707d2cd)

Can you help me how to achieve this?

Right now I use python and Web3.

Thank you very much

1 Answer 1

3

You get the tokens that make up the trading pair by calling following lines on the pair contract:

token0 = contract.functions.token0().call()
token1 = contract.functions.token1().call()

I used the code format you defined in your question above. In your example, the Razor token could be either token0 or token1, depending on the way that pair contract was initialized.

4
  • 3
    Thank you so much for your answer. It works. Unfortunately I cannot upvote your comment, as I do not have enough rep:(
    – Impaulator
    Commented Jun 10, 2021 at 7:52
  • 1
    No worries, happy to help. Commented Jun 10, 2021 at 11:23
  • 1
    'sok I'll do it for ya ;)
    – P i
    Commented Jun 15, 2021 at 9:19
  • @AhmedIhsanTawfeeq, can you please take a look at this? stackoverflow.com/questions/72040453/…
    – rbutrnz
    Commented May 1, 2022 at 23:40

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.