Javascript

Uniswap ‘PairCreated’ 事件監聽器 Temperamental

  • May 12, 2021

誰能推斷出為什麼這沒有向我顯示 Uniswap 上的所有 PairCreated?這似乎很奇怪,因為我看到它在一天中工作一兩次,並為“PairCreated”輸出了一個日誌,但我知道還有更多需要添加!通常每15分鐘左右一次。

這是腳本的開頭…


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 **`);
   ...

有誰知道為什麼這可能不起作用?我從儲存庫中獲取了這個,不是我的所有程式碼,但我了解所有這些 - 或者至少我認為我了解。

問題似乎是助記符與“收件人”錢包不匹配。

引用自:https://ethereum.stackexchange.com/questions/96677