ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.94k stars 1.85k forks source link

Using providers.AlchemyWebSocketProvider for getLogs kills process without error #2235

Open jappyjan opened 2 years ago

jappyjan commented 2 years ago

Describe the bug When using the providers.AlchemyWebSocketProvider class as provider for ethers to fetch logs (only certain request, example provided below) the request just terminates the current process (NodeJS) without throwing any error, attaching a debug event listener with .on('debug', ...) shows that the request is sent but after that, nothing happens (and the process is not killed, just no further processing happening)

Reproduction steps

import 'websocket-polyfill';
import { providers} from 'ethers';

const alchemyAPIKey = 'some valid alchemy api key';
const nftTransferEventTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
const contractAddress = '0x8460bb8eb1251a923a31486af9567e500fc2f43f';
const fromBlock = 13091482;
const toBlock = 13091982;

async function test() {
   const provider = new providers.AlchemyWebSocketProvider('homestead', alchemyAPIKey);
   const logs = await provider.getLogs({
       fromBlock,
       address: contractAddress,
       toBlock,
       topics: [nftTransferEventTopic],
     });
}

test().catch(e => {
   console.error(e);
   process.exit(1);
}

Environment: NodeJS 14.17.6 Both on AWS Lambda and Local (MacOS)

Search Terms Alchemy, Socket, WebSocket, Process Termination, getLogs, logs

jappyjan commented 2 years ago

i can confirm that the exact same request works perfectly when using the "normal" AlchemyProvider