How to use web3-provider-engine - 10 common examples

To help you get started, we’ve selected a few web3-provider-engine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LimeChain / etherlime / packages / etherlime / cli-commands / etherlime-test / etherlime-coverage.js View on Github external
ignoreFilesGlobs: ['**/node_modules/**']
	}

	if (ignoreFiles) {
		ignoreFiles = ignoreFiles.split(',')
		ignoreFiles = ignoreFiles.map(file => "**/" + file)
		coverageSubproviderConfig.ignoreFilesGlobs = coverageSubproviderConfig.ignoreFilesGlobs.concat(ignoreFiles)
	}
		
	global.coverageSubprovider = new CoverageSubprovider(
		artifactAdapter,
		defaultFromAddress,
		coverageSubproviderConfig
	);
	provider.addProvider(global.coverageSubprovider);
	provider.addProvider(new RpcProvider({ rpcUrl: `http://localhost:${port}` }));
	global.provider = provider;

	// start pulling blocks
	provider.start();
	return provider
}
github DigixGlobal / truffle-lightwallet-provider / src / index.js View on Github external
init(cb) {
    if (this.initialized) { return cb(); }
    this.initialized = true;
    this.opts.serialized = fs.readFileSync(this.opts.keystore).toString();
    this.opts.ks = Lightwallet.keystore.deserialize(this.opts.serialized);
    // this.opts.addresses = this.opts.ks.getAddresses().map(a => `0x${a}`);
    this.opts.addresses = this.opts.ks.getAddresses().map(a => a); // removed prefix 0x
    // pass opts
    const { pollingInterval } = this.opts;
    this.engine = new ProviderEngine({ pollingInterval });
    this.engine.addProvider(new FilterProvider());
    this.engine.addProvider(new NonceSubprovider());
    this.engine.addProvider(new LighwalletSubprovider(this.opts));
    this.engine.addProvider(new RpcSubprovider(this.opts));
    // this.engine._fetchLatestBlock();
    this.engine.start();
    if (this.opts.prefund) {
      console.log(`Ensuring all lightwallet accounts have ${this.opts.prefund / 1e18} Ether`);
      return prefund(this.opts).then(cb);
    }
    return cb();
  }
  send() {
github DigixGlobal / truffle-lightwallet-provider / src / index.js View on Github external
init(cb) {
    if (this.initialized) { return cb(); }
    this.initialized = true;
    this.opts.serialized = fs.readFileSync(this.opts.keystore).toString();
    this.opts.ks = Lightwallet.keystore.deserialize(this.opts.serialized);
    // this.opts.addresses = this.opts.ks.getAddresses().map(a => `0x${a}`);
    this.opts.addresses = this.opts.ks.getAddresses().map(a => a); // removed prefix 0x
    // pass opts
    const { pollingInterval } = this.opts;
    this.engine = new ProviderEngine({ pollingInterval });
    this.engine.addProvider(new FilterProvider());
    this.engine.addProvider(new NonceSubprovider());
    this.engine.addProvider(new LighwalletSubprovider(this.opts));
    this.engine.addProvider(new RpcSubprovider(this.opts));
    // this.engine._fetchLatestBlock();
    this.engine.start();
    if (this.opts.prefund) {
      console.log(`Ensuring all lightwallet accounts have ${this.opts.prefund / 1e18} Ether`);
      return prefund(this.opts).then(cb);
    }
    return cb();
  }
  send() {
github 0xchange / 0xchange / src / store / actions.js View on Github external
connect ({dispatch, commit, getters, state}) {
    let providerEngine = null
    if (window.web3) {
      providerEngine = window.web3.currentProvider
    } else {
      const ROPSTEN_ENDPOINT = 'https://infura.io'

      providerEngine = new ProviderEngine()
      providerEngine.addProvider(new FilterSubprovider())
      providerEngine.addProvider(new RpcSubprovider({rpcUrl: ROPSTEN_ENDPOINT}))
      providerEngine.start()
    }

    zeroEx = new ZeroEx(providerEngine)
    zeroEx._web3Wrapper.web3.version.getNetwork((error, response) => {
      if (error) console.error(error)
      if (parseInt(response) === 42 && window.location.hostname !== 'kovan.0xchange.me') {
        window.location.href = 'https://kovan.0xchange.me'
      } else if (parseInt(response) === 1 && window.location.hostname === 'kovan.0xchange.me') {
        window.location.href = 'https://0xchange.me'
      }
    })
    // commit('SET_ZERO_EX', zeroEx)
    // 3117574 kovan
    // 4145578 mainnet
github ConsenSys / web3studio-bootleg / packages / bootleg-common / truffle-config.js View on Github external
provider: () => {
          if (!testProviderStarted) {
            // Within this function to not start the provider until it's needed
            testProvider.addProvider(
              new WebsocketProvider({ rpcUrl: 'http://localhost:7545' })
            );

            testProvider.start(err => {
              testProviderStarted = true;

              if (err !== undefined) {
                // eslint-disable-next-line no-console
                console.log('Failed to start provider', err);
                process.exit(1);
              }
            });
          }

          return testProvider;
        },
        network_id: '*'
github celo-org / celo-monorepo / packages / protocol / truffle-config.js View on Github external
isVerbose: true,
          ignoreFilesGlobs: [
            // Proxies
            '**/*Proxy.sol',

            // Test contracts
            '**/test/*.sol',

            // Interfaces
            '**/interfaces/*.sol',
          ],
        })
        coverageProvider.addProvider(global.coverageSubprovider)

        coverageProvider.addProvider(
          new WebsocketSubprovider({
            rpcUrl: `http://localhost:${defaultConfig.port}`,
            debug: false,
          })
        )

        coverageProvider.start((err) => {
          if (err !== undefined) {
            // tslint:disable-next-line: no-console
            console.error(err)
            process.exit(1)
          }
        })
        /**
         * HACK: Truffle providers should have `send` function, while `ProviderEngine` creates providers with `sendAsync`,
         * but it can be easily fixed by assigning `sendAsync` to `send`.
         */
github DigixGlobal / truffle-lightwallet-provider / src / index.js View on Github external
init(cb) {
    if (this.initialized) { return cb(); }
    this.initialized = true;
    this.opts.serialized = fs.readFileSync(this.opts.keystore).toString();
    this.opts.ks = Lightwallet.keystore.deserialize(this.opts.serialized);
    // this.opts.addresses = this.opts.ks.getAddresses().map(a => `0x${a}`);
    this.opts.addresses = this.opts.ks.getAddresses().map(a => a); // removed prefix 0x
    // pass opts
    const { pollingInterval } = this.opts;
    this.engine = new ProviderEngine({ pollingInterval });
    this.engine.addProvider(new FilterProvider());
    this.engine.addProvider(new NonceSubprovider());
    this.engine.addProvider(new LighwalletSubprovider(this.opts));
    this.engine.addProvider(new RpcSubprovider(this.opts));
    // this.engine._fetchLatestBlock();
    this.engine.start();
    if (this.opts.prefund) {
      console.log(`Ensuring all lightwallet accounts have ${this.opts.prefund / 1e18} Ether`);
      return prefund(this.opts).then(cb);
    }
    return cb();
  }
  send() {
github 0xchange / 0xchange / src / store / actions.js View on Github external
connect ({dispatch, commit, getters, state}) {
    let providerEngine = null
    if (window.web3) {
      providerEngine = window.web3.currentProvider
    } else {
      const ROPSTEN_ENDPOINT = 'https://infura.io'

      providerEngine = new ProviderEngine()
      providerEngine.addProvider(new FilterSubprovider())
      providerEngine.addProvider(new RpcSubprovider({rpcUrl: ROPSTEN_ENDPOINT}))
      providerEngine.start()
    }

    zeroEx = new ZeroEx(providerEngine)
    zeroEx._web3Wrapper.web3.version.getNetwork((error, response) => {
      if (error) console.error(error)
      if (parseInt(response) === 42 && window.location.hostname !== 'kovan.0xchange.me') {
        window.location.href = 'https://kovan.0xchange.me'
      } else if (parseInt(response) === 1 && window.location.hostname === 'kovan.0xchange.me') {
        window.location.href = 'https://0xchange.me'
      }
    })
    // commit('SET_ZERO_EX', zeroEx)
    // 3117574 kovan
    // 4145578 mainnet
    // zeroEx.exchange.getLogsAsync('LogFill', {fromBlock: 4219261, toBlock: 'latest'}, {}).then((logs) => {
github KeySplit / dapp / src / Keysplit / app.js View on Github external
// BUG: This never finds window.web3, and thus always falls back to localStorage keys
      this.web3 = new Web3(window.web3.currentProvider);
    } else {
      var privateKey = options.privateKey || localStorage.getItem("localPrivateKey");
      if(!privateKey) {
        privateKey = Wallet.generate().getPrivateKeyString().slice(2);
        if(localStorage) {
        localStorage.setItem("localPrivateKey", privateKey)}
      }
      // This uses web3-provider-engine and ethereumjs-wallet to construct a
      // wallet in-browser, without needing Metamask, Toshi, etc.
      //
      // Note that the current version of ethereumjs-wallet on npm has a bug,
      // but the latest on Github works just fine.
      var wallet = Wallet.fromPrivateKey(new Buffer(privateKey, "hex"));
      this.engine = new ProviderEngine();
      this.web3 = new Web3(this.engine);
      console.log(this.web3)
      // static results
      this.engine.addProvider(new FixtureSubprovider({
        web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
        net_listening: true,
        eth_hashrate: '0x00',
        eth_mining: false,
        eth_syncing: true,
      }))

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

      // id mgmt
      this.engine.addProvider(new WalletSubprovider(wallet, {}))
github TPL-protocol / tpl-contracts / src / App.js View on Github external
} else if (props.connectionType === 'inject') {
      // set up the injected web3 object in the event that it indeed exists
      if (typeof window.web3 !== 'undefined' &&
          typeof window.web3.currentProvider !== 'undefined') {
        // TODO: how can we support a ledger AND the current provider?
        console.log('found existing web3 provider, initializing...')
        this.web3 = new Web3(window.web3.currentProvider)

        // TODO: can we detect if the current provider is websocket-enabled?
        console.log(`attempting to connect event listener to websocket provider at ${infura}...`)
        this.wsWeb3 = new Web3(new Web3.providers.WebsocketProvider(infura))
      }
    } else if (props.connectionType === 'ledger') {
      // connect to the ledger via u2f, then add infura subprovider & websocket
      console.log('attempting to connect to ledger...')
      const engine = new ProviderEngine()
      const getTransport = () => TransportU2F.create(1000, 2000)
      const ledger = createLedgerSubprovider(getTransport, {
        networkId,
        accountsLength: config.ledgerAccountsLength,
        accountsOffset: config.ledgerAccountsOffset
      })
      engine.addProvider(ledger)

      console.log(`attempting to connect to provider at ${infura}...`)
      let infuraWsProvider = new WebsocketSubprovider({ rpcUrl: infura })
      /* these commands don't work, need to monitor websocket connection health

      infuraWsProvider.on('start', e => console.error('WS start:', e))
      infuraWsProvider.on('error', e => console.error('WS error:', e))
      infuraWsProvider.on('end', e => console.error('WS end:', e))