Skip to main content
Version: 2.2

How to get Pancakeswap V1 pair address

Don't have an API key yet?

Start using this API for your project today.

Get your free API key

Step 1: Setup Moralis

Read the article Setting Up Moralis: Getting Started and make sure to finish all the steps. Only after that you can go ahead to complete this guide.

Step 2: Get Pair Address of A Pancakeswap V1 Liquidity Pool

In order to get pair address of a liquidity, Moralis provides you a getPairAddress endpoint to do so.

Here you'll need three parameters: token0, token1 and address.

Once you've obtained all three parameters, you can copy the following code:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const chain = EvmChain.BSC;

// token 0 address, e.g. WBNB token address
const token0Address = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";

// token 1 address, e.g. LINK token address
const token1Address = "0xF8A0BF9cF54Bb92F17374d9e9A321E6a111a51bD";

const response = await Moralis.EvmApi.defi.getPairAddress({
token0Address,
token1Address,
chain,
exchange: "pancakeswapv1",
});

console.log(response.toJSON());
};

runApp();

Step 3: Run the script

To run the script, enter the following command:

node index.js

In your terminal, you should see the following JSON response:

{
"token0": {
"address": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
"name": "Wrapped BNB",
"symbol": "WBNB",
"logo": null,
"logo_hash": null,
"thumbnail": null,
"decimals": "18",
"block_number": "8242108",
"validated": 1,
"created_at": "2022-01-20T10:41:03.034Z"
},
"token1": {
"address": "0xf8a0bf9cf54bb92f17374d9e9a321e6a111a51bd",
"name": "ChainLink Token",
"symbol": "LINK",
"logo": null,
"logo_hash": null,
"thumbnail": null,
"decimals": "18",
"block_number": "8242108",
"validated": 1,
"created_at": "2022-01-20T10:41:03.034Z"
},
"pairAddress": "0xaebe45e3a03b734c68e5557ae04bfc76917b4686"
}

Congratulations 🥳 You just get the pair address of a Pancakeswap V1 liquidity pool with just a few lines of code using the Moralis DeFi API!

Youtube Video

API Reference

If you want to know more details on the endpoint and optional parameters, check out:

Support

If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.