From 7600605103e39aec0a79e0c69a17d0e6fb97fb10 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sun, 1 Aug 2021 03:16:11 -0300 Subject: [PATCH] Add support for ws communication with erigon --- src/useProvider.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/useProvider.ts b/src/useProvider.ts index c6a3a5c..183f51f 100644 --- a/src/useProvider.ts +++ b/src/useProvider.ts @@ -33,7 +33,12 @@ export const useProvider = ( setConnStatus(ConnectionStatus.CONNECTING); const tryToConnect = async () => { - const provider = new ethers.providers.JsonRpcProvider(erigonURL); + let provider: ethers.providers.JsonRpcProvider; + if (erigonURL?.startsWith("ws://") || erigonURL?.startsWith("wss://")) { + provider = new ethers.providers.WebSocketProvider(erigonURL); + } else { + provider = new ethers.providers.JsonRpcProvider(erigonURL); + } // Check if it is at least a regular ETH node let blockNumber: number = 0;