Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniswap getPair() does not deliver address(0) #144

Open
repomani opened this issue Dec 24, 2021 · 1 comment
Open

Uniswap getPair() does not deliver address(0) #144

repomani opened this issue Dec 24, 2021 · 1 comment

Comments

@repomani
Copy link

repomani commented Dec 24, 2021

I am currently testing the Uniswap function getPair()

mapping(address => mapping(address => address)) public override getPair;

and calling it from UI like this:

   const pairAddress = await this.state.factory.getPair(
            this.state.tokenAData.address,
            this.state.tokenBData.address
          );

For some reason, I am not always getting address(0) like in the documentation explained.

Using ether.js to create the instance:

 const factory = new ethers.Contract(
    this.isAddress(REACT_APP_FACTORY_ADDRESS),
    Factory.abi,
    signer
  );

I deployed a fresh contract and cleared and removed the cache but getting always an address, e.g. "0x1c1Cb37dCe1b1cFF98d798C670D0B2f790141b9a". Is there any other way to find out if the pair address exists or not?

Here is my hardhat.config.ts


import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import { config as dotenvConfig } from 'dotenv';
import { resolve } from 'path';

dotenvConfig({ path: resolve(__dirname, './.env') });

task('accounts', 'Prints the list of accounts', async (args, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  networks: {
    localhost: {
      url: 'http://127.0.0.1:8545',
      chainId: 31337,
    },
    testnet: {
      url: 'https://speedy-nodes-nyc.moralis.io/{key}/bsc/testnet',
      chainId: 97,
      accounts: [process.env.TEST_NET_KEY],
    },
  },
  solidity: {
    version: '0.8.0',
    settings: {
      optimizer: {
        enabled: true,
        runs: 1000,
      },
    },
  },
  paths: {
    sources: './src/contracts',
    tests: './src/tests',
    cache: './cache',
    artifacts: './src/abi',
  },
  mocha: {
    timeout: 20000,
  },
};

Start: npx hardhat node
Deploy: npx hardhat run --network localhost src/scripts/deploy.ts

@ghost
Copy link

ghost commented Dec 31, 2023

Because when there is a pair, it is not an address(0) but a pair address.

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

No branches or pull requests

1 participant