I'm trying to get the pair address if the USDC / USDT pair on uniswap using the v2 core. The pair address exists on uniswap but when i run the code it returns me a null address (0x0000000000000000000000000000000000000000). Im using the goerli testnet
The main file
const IUniswapV2Pair = require("@uniswap/v2-core/build/IUniswapV2Pair.json");
const IERC20 = require("@openzeppelin/contracts/build/contracts/ERC20.json");
const { provider, uFactory } = require("./config");
const ethers = require("ethers");
let tokenA, tokenB;
const getTokenAndContract = async (
_tokenAAddress,
_tokenBAddress,
_provider
) => {
const tokenAcontract = new ethers.Contract(
_tokenAAddress,
IERC20.abi,
_provider
);
const tokenBcontract = new ethers.Contract(
_tokenBAddress,
IERC20.abi,
_provider
);
tokenA = {
address: _tokenAAddress,
decimals: 18,
};
tokenB = {
address: _tokenBAddress,
decimals: 18,
};
};
const tokensAndContract = getTokenAndContract(
process.env.TOKEN_A,
process.env.TOKEN_B,
provider
);
const main = async () => {
const pairAddress = await uFactory.getPair(tokenA.address, tokenB.address);
console.log(pairAddress); // output = 0x0000000000000000000000000000000000000000
};
main();
the config file
const IUniswapV2Factory = require("@uniswap/v2-core/build/IUniswapV2Factory.json");
const hre = require("hardhat");
let provider;
provider = new hre.ethers.providers.WebSocketProvider(
`wss://eth-goerli.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
);
console.log("uFactory");
const uFactory = new hre.ethers.Contract(
// the address is 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f
process.env.UNISWAP_FACTORY_ADDRESS,
IUniswapV2Factory.abi,
provider
);
module.exports = { provider, uFactory };
Is my code wrong?
I looked up the uniswap docs and i followed it and checked that the pair with the 2 addresses existed but it kept returning me 0x0000000000000000000000000000000000000000.