moralis-web3-providers-ws

This is a fork of web3-providers-ws that uses https://github.com/MoralisWeb3/WebSocket-Node

This is a websocket provider sub-package for web3.js.

Please read the documentation for more.

Installation

Node.js

npm install moralis-web3-providers-ws

Usage

const MoralisWeb3ProvidersWs = require('moralis-web3-providers-ws');

const options = {
    // Enable keepalive 
    clientConfig: {
        keepalive: true,
        keepaliveInterval: 60000,
        keepaliveForce: true
    },
    // Enable auto reconnection
    reconnect: {
        auto: true,
        delay: 5000, // ms
        maxAttempts: 5,
        onTimeout: false
    }
};

const wsProvider = new MoralisWeb3ProvidersWs('ws://localhost:8546', options);

Usage with Web3

const Web3 = require('web3');
const web3 = new Web3(wsProvider);

Usage with Ethers.js

const ethers = require('ethers');
const provider = new ethers.providers.Web3Provider(wsProvider);

Additional client config options can be found here.

Types

All the TypeScript typings are placed in the types folder.