Skip to content

Reliable web3 provider that uses multiple RPC APIs and switches between them in case of failure

License

Notifications You must be signed in to change notification settings

dreamteam-gg/web3-zeus-provider

Repository files navigation

Web3 Zeus Provider

Build Status

Reliable Web3 provider which features:

  • Connects to multiple RPC APIs and switches between them when some are unavailable.
  • Allows to specify private keys for signing transactions.

Primarily made for server-side usage (as it depends on a heavy library...).

Installation

npm install --save web3-zeus-provider

Usage

const ZeusProvider = require("web3-zeus-provider");
const zeusProvider = new ZeusProvider({
    rpcApis: [
        "https://mainnet.infura.io",
        "https://localhost:8545"
    ],
    privateKeys: [ // Accounts which are used for offline transaction signing
        "FCAFC28AF87287F3AB81554C2DF38C3FCE6E2C7654DB7710243A2D52A9EDF441"
    ],
    onRpcProviderChange: function ({ from, to, error, response }) {
        console.log(`RPC provider switched from ${ from } to ${ to } because of ${ error }`);
    }
});
const Web3 = require("web3");
const web3 = new Web3(zeusProvider);

// Example
web3.eth.getBlockNumber().then((blockNumber) => {
    console.log(blockNumber);
});

// ...

zeusProvider.terminate(); // Stop internal provider engine listeners once you don't need provider anymore

Development

Develop using local environment or Docker:

bash docker.sh

License

MIT (c) Nikita Savchenko

About

Reliable web3 provider that uses multiple RPC APIs and switches between them in case of failure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages