3

where can I find the smart contract address of all (or the major) coin pairs of the pancakeswap AMM. I can't find it anywhere and searching on google yields random articles.

4 Answers 4

4

The factory contract - PancakeFactory - is here:

https://bscscan.com/address/0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73

If you read the contract, you'll see that allPairsLength gives you 14,690 pairs. This refers to the number of PancakePair-type contracts.

The addresses can be found by reading the allPairs array in PancakeFactory by specifying the index you want. In the absence of anything clever, like Uniswap's Subgraph API (see "All Pairs In Uniswap") you'll probably just have to write a simple looping function to iterate through the array.

Edit:

Actually, this API will give you the top 1,000 pairs... (sorted by reserves)

https://api.pancakeswap.info/api/v2/pairs

Filter on pair_address.

1
1

You can use https://bscscan.com/ for Binance Contracts. You can use https://etherscan.io/ for Ethereum Contracts.

Here pancakeswap: https://bscscan.com/token/0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82

2
  • Does not provide a simple way to discover price pairs, though.
    – Gajus
    May 17, 2021 at 2:06
  • I'll downvote because this is vague and explains nothing. You told 3 obvious things.
    – Magno C
    Apr 20, 2022 at 0:54
1

In addition to what the others answered, if you just want to check if a particular pair exists, you can calculate the address for it in the following way:

address factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
address token0 = 0xCAFE000000000000000000000000000000000000; // change me!
address token1 = 0xF00D000000000000000000000000000000000000; // change me!

address pair = address(uint(keccak256(abi.encodePacked(
  hex'ff',
  factory,
  keccak256(abi.encodePacked(token0, token1)),
  hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
))));

Note that:

  • token0 must be strictly less than token1 by sort order.
1

calculate pair address with token0 and token1 on pancakeswap:

address factory = 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73;
address token0 = 0xCAFE000000000000000000000000000000000000; // change me!
address token1 = 0xF00D000000000000000000000000000000000000; // change me!

address pair = address(uint(keccak256(abi.encodePacked(
  hex'ff',
  factory,
  keccak256(abi.encodePacked(token0, token1)),
  hex'0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5' // ref: https://github.com/pancakeswap/pancake-swap-sdk/blob/7d81106174e16d1f1c6c91a93558736282a39ec1/src/constants.ts#L24
))));

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.