1

Can anyone deduce why this doesn't show me all the PairCreated on Uniswap? It seems odd as I have seen it work once or twice during the day and ouput a log for a 'PairCreated', but I know there are many more that get added! Normally every 15mins or so.

Here is the beginning of the script...


const ethers = require('ethers');
const isTesting = false; // Kovan for testnet

const infuraWSS = isTesting ? 'wss://kovan.infura.io-------------' : 'wss://mainnet.infura.io----------------';

// SETUP
const addresses = {
  WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
  factory: '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f', //uniswap v2 factory
  router: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', //uniswap v2 router
  recipient: '-------------------' //this address receives the tokens (currently my main test account)
}

const mnemonic = '----------------------';

const provider = new ethers.providers.WebSocketProvider(infuraWSS);
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
const account = wallet.connect(provider);

const factory = new ethers.Contract(
  addresses.factory,
  ['event PairCreated(address indexed token0, address indexed token1, address pair, uint)'],
  account
);
const router = new ethers.Contract(
  addresses.router,
  [
    'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
    'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
  ],
  account
);

factory.on('PairCreated', async (token0, token1, pairAddress) => {
  console.log(`** New Pair Detected **`);
    ...

Does anyone know why this might not be working? I took this from a repository, not all my code but I understand all of it - or at least think I do.

1
1

The issue seems to have been that the mnemonic did not match the 'recipient' wallet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.