title: How to decode Token Address from a given Pair Address in web3
body: <p>What I am trying to accomplish is to get the Contract Address <code>0x1ada8bb610c59aae25d8dd8f354282f5693cefb1</code>  given the LP Pair address <code>0x0D0b63b32595957ae58D4dD60aa5409E79A5Aa96</code> in (Token/BNB) pair. My Current Code is getting me nowhere. Ideas will be very helpful.</p>
  <p>Current Code:</p>
  <pre><code>from web3 import Web3, HTTPProvider
  import json
  
  bsc = 'https://bsc-dataseed.binance.org/'    
  web3 = Web3(Web3.HTTPProvider(bsc))
  print(&quot;Connected to BSC: &quot;, web3.isConnected())
  
  address = &quot;0x0d0b63b32595957ae58d4dd60aa5409e79a5aa96&quot;    #-- LP Pair Address to check
  
  #-- 0x1ada8bb610c59aae25d8dd8f354282f5693cefb1  Token Address
  #-- 0x0D0b63b32595957ae58D4dD60aa5409E79A5Aa96  Token LP Pair Address
  
  abi = json.loads('[{&quot;inputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;_feeToSetter&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;nonpayable&quot;,&quot;type&quot;:&quot;constructor&quot;},{&quot;anonymous&quot;:false,&quot;inputs&quot;:[{&quot;indexed&quot;:true,&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;token0&quot;,&quot;type&quot;:&quot;address&quot;},{&quot;indexed&quot;:true,&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;token1&quot;,&quot;type&quot;:&quot;address&quot;},{&quot;indexed&quot;:false,&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;pair&quot;,&quot;type&quot;:&quot;address&quot;},{&quot;indexed&quot;:false,&quot;internalType&quot;:&quot;uint256&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;uint256&quot;}],&quot;name&quot;:&quot;PairCreated&quot;,&quot;type&quot;:&quot;event&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[],&quot;name&quot;:&quot;INIT_CODE_PAIR_HASH&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;bytes32&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;bytes32&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[{&quot;internalType&quot;:&quot;uint256&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;uint256&quot;}],&quot;name&quot;:&quot;allPairs&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[],&quot;name&quot;:&quot;allPairsLength&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;uint256&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;uint256&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:false,&quot;inputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;tokenA&quot;,&quot;type&quot;:&quot;address&quot;},{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;tokenB&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;name&quot;:&quot;createPair&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;pair&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;nonpayable&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[],&quot;name&quot;:&quot;feeTo&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[],&quot;name&quot;:&quot;feeToSetter&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;address&quot;},{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;name&quot;:&quot;getPair&quot;,&quot;outputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:false,&quot;inputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;_feeTo&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;name&quot;:&quot;setFeeTo&quot;,&quot;outputs&quot;:[],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;nonpayable&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:false,&quot;inputs&quot;:[{&quot;internalType&quot;:&quot;address&quot;,&quot;name&quot;:&quot;_feeToSetter&quot;,&quot;type&quot;:&quot;address&quot;}],&quot;name&quot;:&quot;setFeeToSetter&quot;,&quot;outputs&quot;:[],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;nonpayable&quot;,&quot;type&quot;:&quot;function&quot;}]')
  
  PCS_FACTORY_ADDRESS=&quot;0xca143ce32fe78f1f7019d7d551a6402fc5350c73&quot;
  PCS_FACTORY_ADDRESS = Web3.toChecksumAddress(PCS_FACTORY_ADDRESS.lower() )
  PCS_FACTORY_CONTRACT = web3.eth.contract(address=PCS_FACTORY_ADDRESS, abi=abi)
  pair_contract = PCS_FACTORY_CONTRACT.functions.allPairs.call()
  contract = web3.eth.contract(address=address , abi=abi)
  
  token0 = contract.functions.token0().call()
  token1 = contract.functions.token1().call()
  print (token0)  #-- could be token Address or LP Pair Address
  print (token1)  #-- could token Address or LP Pair Address
  </code></pre>
  <p>Needed Output:</p>
  <pre><code>Pair Address  : 0x0d0b63b32595957ae58d4dd60aa5409e79a5aa96  #-- LP Pair Address / Given input
  Token Address : 0x1ada8bb610c59aae25d8dd8f354282f5693cefb1  #-- token Address (output)
  </code></pre>