reconnect for ws
This commit is contained in:
parent
eb6b1fe0d1
commit
cea18e6a5f
@ -5,7 +5,14 @@ import Web3 from 'web3';
|
|||||||
const rpcUrl = process.env.RPC_URL || 'ws://localhost:8545';
|
const rpcUrl = process.env.RPC_URL || 'ws://localhost:8545';
|
||||||
|
|
||||||
// Create a new web3 instance
|
// 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
|
// Get the current gas price in gwei
|
||||||
async function getGasPrice() {
|
async function getGasPrice() {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Client, EmbedBuilder, TextChannel } from 'discord.js';
|
import { EmbedBuilder, TextChannel } from 'discord.js';
|
||||||
import { getGasPricesInGwei } from './blockchain';
|
import { getGasPricesInGwei } from './blockchain';
|
||||||
import redisClient from './redis';
|
import redisClient from './redis';
|
||||||
|
import { DiscordClient } from './discordClient';
|
||||||
|
|
||||||
import { GasAlert } from '../types/gasAlert';
|
import { GasAlert } from '../types/gasAlert';
|
||||||
|
|
||||||
const createGasPriceChecker = (client: Client) => {
|
const createGasPriceChecker = (client: DiscordClient) => {
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const gasPrices = await getGasPricesInGwei();
|
const gasPrices = await getGasPricesInGwei();
|
||||||
|
Loading…
Reference in New Issue
Block a user