3

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

2

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.

3
  • 3
    Thank you so much for your answer. It works. Unfortunately I cannot upvote your comment, as I do not have enough rep:(
    – Impaulator
    Jun 10 at 7:52
  • 1
    No worries, happy to help. Jun 10 at 11:23
  • 1
    'sok I'll do it for ya ;)
    – P i
    Jun 15 at 9:19

Your Answer

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

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