How to use the web3-provider-engine/subproviders/websocket.js function in web3-provider-engine

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 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 0xProject / dev-tools-truffle-example / truffle-config.js View on Github external
defaultFromAddress,
      {
        isVerbose,
      }
    );
    provider.addProvider(global.coverageSubprovider);
  } else if (mode === "trace") {
    const revertTraceSubprovider = new RevertTraceSubprovider(
      artifactAdapter,
      defaultFromAddress,
      isVerbose
    );
    provider.addProvider(revertTraceSubprovider);
  }
  
  provider.addProvider(new WebsocketSubprovider({ rpcUrl: "http://localhost:8545" }))
}
provider.start(err => {
  if (err !== undefined) {
    console.log(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`.
 */
provider.send = provider.sendAsync.bind(provider);

module.exports = {
  networks: {
    development: {
github mitmedialab / medrec / UserClient / src / Ethereum.js View on Github external
let rawTX = tx.serialize().toString('hex');

          let signedTx = '0x' + signing.signTx(
            vault,
            this.pwDerivedKey,
            rawTX,
            txObject.from.toLowerCase()
          );
          cb(null, signedTx);
        });
      },
    }));

    //data sources
    //this must come as the last component so it doesn't overshadow the wallet
    this.engine.addProvider(new WebSocketSubprovider({
      rpcUrl: 'ws://localhost:8546',
    }));

    //log new blocks
    this.engine.on('block', (block) => {
      let newPendTrans = [];
      this.pendingTransactions.forEach(txObj => {
        this.web3.eth.getTransactionReceipt(txObj.txid).then(receipt => {
          if(receipt && receipt.blockHash) {
            txObj.resolve(receipt);
          }else {
            newPendTrans.push(txObj);
          }
        });
      });
      this.pendingTransactions = newPendTrans;