Uniswap / v2-core

🦄 🦄 Core smart contracts of Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
2.89k stars 3.11k forks source link

getPair call via Ethers.Contract does not return a pair address #171

Open Samboy76 opened 1 year ago

Samboy76 commented 1 year ago

Hi,

When I call following getPair under uniswapFactory contract I created via ethers.Contract in my javascript it doesn´t return any pair address.

const UniswapV2Factory = require("./build/contracts/IUniswapV2Factory.json");

uniswapFactory = new ethers.Contract(
        '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f', // uniswap v2 factory address in Etherscan mainnet
        UniswapV2Factory.abi, wallet
    );

    const pairAddress = await uniswapFactory.getPair(wethAddress, otherAddress);
    const pair = new Contract(pairAddress, UniswapV2Pair.abi, wallet);
    console.log("yeah2!");

Strange thing is if I removed awaitkeywork it returns Promise { }.

However, if I run await uniswapFactory.getPair(wethAddress, otherAddress); directly under Truffle console it resolves the pair address correctly.

Any suggestions would be greatly appreciated as it´s been bugging me also for a very long time.

Thank you

ghost commented 6 months ago

Depends on the wallet provider ( or an object ) that you are connecting with.

Make sure to check if the provider node could be connected, and using the right network.

Also, await keyword is essential since it resolves promise object ( since it is a remote call that uses node ).