Skip to content

Instantly share code, notes, and snippets.

@duanescarlett
Last active June 16, 2022 15:36
Show Gist options
  • Save duanescarlett/7521dccf33ca77828ae9ff82a47be4ee to your computer and use it in GitHub Desktop.
Save duanescarlett/7521dccf33ca77828ae9ff82a47be4ee to your computer and use it in GitHub Desktop.
Get Liquidity Pool address
const ethers = require('ethers')
const { toChecksumAddress } = require('ethereum-checksum-address')
require('dotenv').config()
const main = async () => {
// Connect to an EVM network
const provider = new ethers.providers.JsonRpcProvider(`https://rpc.ankr.com/bsc`)
// Create a Factory contract abi
const IPair = [
'function getPair(address token0, address token1) external view returns (address)',
'function allPairs(uint256 val) external view returns (address)',
'event PairCreated(address indexed token0, address indexed token1, address pair, uint)',
]
// Checksum the pancake Factory address
const FactoryAddr = toChecksumAddress('0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73')
// Make a js obj of a factory contract
const LP = new ethers.Contract(FactoryAddr, IPair, provider)
// Checksum the token addresses
let addr0 = toChecksumAddress('0x9B3a01F8b4aBD2E2a74597B21b7C269ABf4E9f41')
let addr1 = toChecksumAddress('0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56')
// Get the LP pair address
const pairAddress = await LP.getPair(addr1, addr0)
console.log("Pair Address:=> ", pairAddress)
}
main()
.then(() => process.exit(0))
.catch((err) => {
console.error(err)
process.exit(1)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment