reconnect for ws

This commit is contained in:
GooeyTuxedo 2023-04-17 22:51:24 -07:00
parent eb6b1fe0d1
commit cea18e6a5f
2 changed files with 11 additions and 3 deletions

View File

@ -5,7 +5,14 @@ import Web3 from 'web3';
const rpcUrl = process.env.RPC_URL || 'ws://localhost:8545';
// Create a new web3 instance
const web3 = new Web3(rpcUrl);
const web3 = new Web3(new Web3.providers.WebsocketProvider(rpcUrl, {
reconnect: {
auto: true,
delay: 5000,
maxAttempts: 5,
onTimeout: false
}
}));
// Get the current gas price in gwei
async function getGasPrice() {

View File

@ -1,10 +1,11 @@
import { Client, EmbedBuilder, TextChannel } from 'discord.js';
import { EmbedBuilder, TextChannel } from 'discord.js';
import { getGasPricesInGwei } from './blockchain';
import redisClient from './redis';
import { DiscordClient } from './discordClient';
import { GasAlert } from '../types/gasAlert';
const createGasPriceChecker = (client: Client) => {
const createGasPriceChecker = (client: DiscordClient) => {
setInterval(async () => {
try {
const gasPrices = await getGasPricesInGwei();