Skip to content
A JavaScript library for composing Ethereum provider objects using middleware modules.
Branch: master
Clone or download
Latest commit 5f7acf6 Mar 29, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
subproviders subp - fetch - use eth-json-rpc-middleware/fetch Mar 29, 2019
test deps - update eth-json-rpc-filters for fixes Mar 29, 2019
.npmignore npm scripts - add prepublish step and include dist in build Apr 10, 2018
LICENSE Create LICENSE Mar 24, 2018
bower.json updated web3 version to 0.18.4 to support signTransaction, included d… Apr 1, 2017
example.js example - add more example rpcUrls Apr 10, 2018
package-lock.json 15.0.0 Mar 29, 2019
package.json 15.0.0 Mar 29, 2019
zero.js subp - subscriptions - use eth-json-rpc-filters implementation and au… Mar 18, 2019

Web3 ProviderEngine

Greenkeeper badge

Web3 ProviderEngine is a tool for composing your own web3 providers.


Built to be modular - works via a stack of 'sub-providers' which are like normal web3 providers but only handle a subset of rpc methods.

The subproviders can emit new rpc requests in order to handle their own; e.g. eth_call may trigger eth_getAccountBalance, eth_getCode, and others. The provider engine also handles caching of rpc request results.

const ProviderEngine = require('web3-provider-engine')
const CacheSubprovider = require('web3-provider-engine/subproviders/cache.js')
const FixtureSubprovider = require('web3-provider-engine/subproviders/fixture.js')
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js')
const VmSubprovider = require('web3-provider-engine/subproviders/vm.js')
const HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet.js')
const NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker.js')
const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js')

var engine = new ProviderEngine()
var web3 = new Web3(engine)

// static results
engine.addProvider(new FixtureSubprovider({
  web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
  net_listening: true,
  eth_hashrate: '0x00',
  eth_mining: false,
  eth_syncing: true,

// cache layer
engine.addProvider(new CacheSubprovider())

// filters
engine.addProvider(new FilterSubprovider())

// pending nonce
engine.addProvider(new NonceSubprovider())

// vm
engine.addProvider(new VmSubprovider())

// id mgmt
engine.addProvider(new HookedWalletSubprovider({
  getAccounts: function(cb){ ... },
  approveTransaction: function(cb){ ... },
  signTransaction: function(cb){ ... },

// data source
engine.addProvider(new RpcSubprovider({
  rpcUrl: '',

// log new blocks
engine.on('block', function(block){
  console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))

// network connectivity error
engine.on('error', function(err){
  // report connectivity errors

// start polling for blocks

When importing in webpack:

import * as Web3ProviderEngine  from 'web3-provider-engine';
import * as RpcSource  from 'web3-provider-engine/subproviders/rpc';
import * as HookedWalletSubprovider from 'web3-provider-engine/subproviders/hooked-wallet';

Built For Zero-Clients

The Ethereum JSON RPC was not designed to have one node service many clients. However a smaller, lighter subset of the JSON RPC can be used to provide the blockchain data that an Ethereum 'zero-client' node would need to function. We handle as many types of requests locally as possible, and just let data lookups fallback to some data source ( hosted rpc, blockchain api, etc ). Categorically, we don’t want / can’t have the following types of RPC calls go to the network:

  • id mgmt + tx signing (requires private data)
  • filters (requires a stateful data api)
  • vm (expensive, hard to scale)

Change Log

  • uses eth-block-tracker@4, but still provides block body on ('block', 'latest', and 'rawBlock'). Other events ('sync') provide block number hex string instead of block body.
  • SubscriptionsSubprovider automatically forwards events to provider
  • replacing subprovider implementations with those in eth-json-rpc-engine
  • browserify: moved to babelify@10 + @babel/core@7
  • default dataProvider for zero is Infura mainnet REST api
  • websocket support
  • subscriptions support
  • remove solc subprovider
  • removed dist from git (but published in npm module)
  • es5 builds in dist/es5
  • zero + ProviderEngine bundles are es5
  • web3 subprovider renamed to provider subprovider
  • error if provider subprovider is missing a proper provider
  • removed need to supply getAccounts hook
  • fixed hooked-wallet-ethtx message signing
  • fixed hooked-wallet default txParams
  • zero.js - replaced http subprovider with fetch provider (includes polyfill for node).
  • renamed HookedWalletSubprovider personalRecoverSigner to recoverPersonalSignature
  • pollingShouldUnref option now defaults to false
You can’t perform that action at this time.