# Get Pools by Token Addresses

Pump AMM, the native decentralized exchange for Pump.fun tokens, utilizes liquidity pools to facilitate trading. Each pool is defined by a liquidity pair of token mint addresses. This pair is denoted by <mark style="color:yellow;">baseMint</mark> and <mark style="color:yellow;">quoteMint</mark> addresses on Pumpswap. We can add filters to these two fields, to retrieve specific pool details involving a particular liquidity pair.\
For instance we are trying to get liquidity pools involving USDC and SOL, so we filter `baseMint`and `quoteMint`fields using the *\_in* filter.

You can directly copy paste this code on <mark style="color:yellow;">replit</mark> and see it in action.

#### Fetch Pool by Liquidity Pair (USDC-SOL)

{% tabs %}
{% tab title="Code Snippet" %}

<pre class="language-javascript" data-overflow="wrap"><code class="lang-javascript">async function getPoolDetailsByLiquidtyPair(mintAddressA, mintAddressB) {
  const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
    //query to get pool details on PumpSwap by liquidity pair
  const operationsDoc = `
    query MyQuery {
      pump_fun_amm_Pool(where: {base_mint: {_in: ${JSON.stringify([
        mintAddressA,
        mintAddressB,
      ])}}, 
      quote_mint: {_in: ${JSON.stringify([
        mintAddressA,
        mintAddressB,
      ])}}}) 
          {
                base_mint
                creator
                index
                lp_mint
                lp_supply
                pool_base_token_account
                pool_bump
                pool_quote_token_account
                quote_mint
                pubkey
            }
        }
`; //you can cherrypick the fields as per your requirement

  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&#x26;network=mainnet-beta`, //SHYFT's GQL endpoint
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    }
  );

  const { errors, data } = await result.json();

  console.dir(data, { depth: null });
}

<strong>getPoolDetailsByLiquidtyPair("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","So11111111111111111111111111111111111111112");
</strong>//getting USDC_SOL pairs, you can get other tokens by just changing the address
</code></pre>

{% endtab %}

{% tab title="Response" %}

```json
{
  "pump_fun_amm_Pool": [
    {
      "base_mint": 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      "creator": 'erAbhGh5x8ZhSQGpsMcvajKJzHPvoeFxodiVdzWKtzq',
      "index": 0,
      "lp_mint": '9uXagk63fc4nWwY6NuokPnHeXZgzs3HJQ2ymKHpTTkai',
      "lp_supply": 100,
      "pool_base_token_account": '6d1YzpXmCWGmGCwfB5UVfh7SbSMf1Sohjt3NpdCXPLFq',
      "pool_bump": 254,
      "pool_quote_token_account": 'AtoKZgnH6AhdUPbjJ4wx3y4toYYhASXTuLSxF2uQT1Ya',
      "quote_mint": 'So11111111111111111111111111111111111111112',
      "pubkey": '5nmZbfXMdbye1vdpF1BaE1FkqZEnJ8JBFsmS15kENjpb'
    },
    {
      "base_mint": 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      "creator": '2Ugqbvmp7A6iv87R39TNbWy6SDpQ6Usrzqh44hwGCbCx',
      "index": 0,
      "lp_mint": 'DFbx9ZquLYtEdwMDmRCeh3HWeSP942mN7QNZYHyWFHZb',
      "lp_supply": 3162277,
      "pool_base_token_account": 'BcZN6q9DiUzkjbH7ULE2dciriCFiZyfy7ffVcTc9kLs',
      "pool_bump": 255,
      "pool_quote_token_account": 'HuRpXa34FYGzxt5buqRRzFnhu43fGPd79rprYhhevHyN',
      "quote_mint": 'So11111111111111111111111111111111111111112',
      "pubkey": '3AfWfdQfE2sqDkCzyq4YMXdCn52eWzC4RAzkhL8HUpXU'
    },
    //....response shortened
  ]
}

```

{% endtab %}
{% endtabs %}

We can also query liquidity pool involving a particular <mark style="color:yellow;">token address</mark>, for that we would have to filter the `baseMint` or `quoteMint` field using the *\_in* filter.

#### Fetch Pools involving a Token (USDC)

{% tabs %}
{% tab title="Code Snippet" %}

```javascript
async function getPoolsForAToken(mintAddress) {
  const SHYFT_API_KEY = "YOUR_SHYFT_API_KEY";
  //query to get pool details on PumpSwap involving one token
  const operationsDoc = `
		query MyQuery {
            pump_fun_amm_Pool(where: {_or: [{_or: {base_mint: {_eq: ${JSON.stringify(
              mintAddress
            )}}}},{_or: {quote_mint: {_eq: ${JSON.stringify(
    mintAddress
  )}}}}]}) {
                base_mint
                creator
                index
                lp_mint
                lp_supply
                pool_base_token_account
                pool_bump
                pool_quote_token_account
                quote_mint
                pubkey
            }
        }
		`; //you can cherrypick the fields as per your requirement

  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    }
  );

  const { errors, data } = await result.json();

  console.dir(data, { depth: null });
}

getPoolsForAToken("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
//for getting all pools involving USDC
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "pump_fun_amm_Pool": [
    {
      base_mint: 'GbbesPbaYh5uiAZSYNXTc7w9jty1rpg3P9L4JeN4LkKc',
      creator: 'D6XEeGyn9rTe9fdPEoSceY7f13bU4CNcYzwUZMGYm6gk',
      index: 0,
      lp_mint: 'AKWTvBkPzTMwPxsq9FJDg2f53nr9iB8cbEUCWScatGCd',
      lp_supply: 22633637,
      pool_base_token_account: '3Szsf4KVSr7iUjsdsNtqDnHGyL31EUeGFtQKPcKcrbPd',
      pool_bump: 253,
      pool_quote_token_account: 'B41SoqkdY4yHr5o3vybjTqdXufHXnHmuQ1mL9m44Lv1c',
      quote_mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      pubkey: 'GdXPQB45gLE3VxE5NWbvLkmE7gH1rqyABG6dXiizZstE'
    },
    {
      base_mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      creator: '9Er1dZdNR4An4gdPNdePmYw4CbbuqTrQj9h2oA7Zjb12',
      index: 0,
      lp_mint: 'EGxBgRmRha2LTaGSTxdivDzahs63F36iKDL7mu2Uem9f',
      lp_supply: 121655250,
      pool_base_token_account: '2Fna1efUfPujrpCG93kAqQ8x5kAhGjdALcU4G4q68xmK',
      pool_bump: 253,
      pool_quote_token_account: 'FT2b2QAALS9JiHPUFM3ZVKgAqVZ5WVgXHQ9JKoSqxXqy',
      quote_mint: 'So11111111111111111111111111111111111111112',
      pubkey: 'HKgz8ky2dGL8EepSLD9PbhCYHYc1fR193SW8HuhetBnq'
    }
    //...response shortened for visibility
  ] 
}

```

{% endtab %}
{% endtabs %}
