Last active
June 16, 2022 15:36
-
-
Save duanescarlett/7521dccf33ca77828ae9ff82a47be4ee to your computer and use it in GitHub Desktop.
Get Liquidity Pool address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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