Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Fails to return reserve outputs from getReserves() #115

Open
Samboy76 opened this issue Sep 27, 2022 · 1 comment
Open

Fails to return reserve outputs from getReserves() #115

Samboy76 opened this issue Sep 27, 2022 · 1 comment

Comments

@Samboy76
Copy link

Samboy76 commented Sep 27, 2022

Hello,

I have an issue in that I cannot get passed executing code line await pairContract.functions.getReserves(); shown in below code snippet. There is no error caught in trycatch so what am I doing wrong here? Any suggestions please?

const getPair = async (other) => {
	const pairAddress = Pair.getAddress(other, WETH[other.chainId], provider,);
	console.log("pairAddress ", pairAddress);

	const pairContract = new ethers.Contract(
		pairAddress,
		UniswapV2Pair.abi,
		provider,
	);

	console.log("pairContract ", pairContract.address);
	try {
		const reserves = await pairContract.functions.getReserves();
		console.log("reserves ", reserves);
	} catch (error) {
		console.log("error text ", error);
	}
	
	const [reserve0, reserve1] = reserves;
  
	const tokens = [other, WETH[other.chainId]];
	const [token0, token1] = tokens[0].sortsBefore(tokens[1]) ? tokens : [tokens[1], tokens[0]];
  
	const pair = new Pair(new TokenAmount(token0, reserve0), new TokenAmount(token1, reserve1));
	return pair;
};

Truffle v5.5.31 (core: 5.5.31)
Ganache v7.4.3
Solidity - >=0.5.0 <0.9.0 (solc-js)
Node v16.17.0
Web3.js v1.7.4

Thank you

@Samboy76 Samboy76 changed the title Unable to getReserves() Fails to return reserve outputs from getReserves() Sep 27, 2022
@Florian-S-A-W
Copy link

Hi @Samboy76

Did you verify that the Pair address is correct? Does a pair exist for the two tokens?

What version of the SDK are you using? Pair.getAddress only accepts 2 parameters in the latest version.
Please make sure you are using the v2-sdk package and not the deprecated uniswap/sdk

I can not reproduce your issue, calling getReserves on any UniswapV2Pair contract works for me. If the address is correct and the address you are calling is a UniswapV2Pair, this is not an issue with this SDK but either with the RPC provider you are using or with Web3.js.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants