How to use the web3-provider-engine/subproviders/provider.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 daostack / alchemy / src / lib / truffle-hdwallet-provider.ts View on Github external
getPrivateKey: function(address: string, cb: Function) {
        if (!tmp_wallets[address]) { return cb('Account not found'); }
        else { cb(null, tmp_wallets[address].getPrivateKey().toString('hex')); }
      },
      signTransaction: function(txParams: any, cb: Function) {
        let pkey;
        if (tmp_wallets[txParams.from]) { pkey = tmp_wallets[txParams.from].getPrivateKey(); }
        else { cb('Account not found'); }
        var tx = new Transaction(txParams);
        tx.sign(pkey);
        var rawTx = '0x' + tx.serialize().toString('hex');
        cb(null, rawTx);
      }
    }));
    this.engine.addProvider(new FiltersSubprovider());
    this.engine.addProvider(new ProviderSubprovider(new Web3.providers.HttpProvider(provider_url)));
    this.engine.start(); // Required by the provider engine.
  }
github wibsonorg / wibson-core / utils / PrivKeyWalletProvider.js View on Github external
} else {
        cb('Account not found');
      }
      const tx = new Transaction(txParams);
      tx.sign(pkey);
      const rawTx = `0x${tx.serialize().toString('hex')}`;
      cb(null, rawTx);
    },
  }));

  (!shareNonce)
    ? this.engine.addProvider(new NonceSubProvider())
    : this.engine.addProvider(singletonNonceSubProvider);

  this.engine.addProvider(new FiltersSubprovider());
  this.engine.addProvider(new ProviderSubprovider(new Web3.providers.HttpProvider(providerUrl)));
  this.engine.start(); // Required by the provider engine.
}
github Propy / ethereum / truffle.js View on Github external
const privateKey = require('./network_keys/private/rinkeby');
const wallet = ethereumjsWallet.fromPrivateKey(new Buffer(privateKey, "hex"));
const sender = "0x" + wallet.getAddress().toString("hex");

// Using rinkeby testnet
const apiKey = require('./network_keys/api/infura');
const providerUrl = "https://rinkeby.infura.io/" + apiKey;
const engine = new ProviderEngine();

const provider = new Web3.providers.HttpProvider(providerUrl);
const web3 = new Web3(provider);

// filters
engine.addProvider(new FilterSubprovider());
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new Web3Subprovider(provider));
engine.start();  // FIXME: Truffle hangs after compilation/migration because of this


module.exports = {
    networks: {
        development: {
            host: "localhost",
            port: 8545,
            network_id: "*", // Match any network id
            gas: 4000000,
        },
        rinkeby: {
            network_id: 4,
            provider: () => engine,
            from: sender,
            gas: 4712388,
github trustwallet / trust-web3-provider / JS / src / index.js View on Github external
constructor(options, syncOptions) {
    super();
    const engine = this
    const web3 = new Web3(this)
    const { rpcUrl } = options

    context.web3 = web3
    globalSyncOptions = syncOptions

    engine.addProvider(new CacheSubprovider())
    engine.addProvider(new SubscriptionsSubprovider())
    engine.addProvider(new FilterSubprovider())
    engine.addProvider(hookedSubProvider = new HookedWalletSubprovider(options))
    engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl)))
    engine.on('error', err => console.error(err.stack))
    engine.isTrust = true
    engine.start()
  }
github MetaMask / gaba / src / network / NetworkController.ts View on Github external
private setupInfuraProvider(type: NetworkType) {
		const infuraProvider = createInfuraProvider({ network: type });
		const infuraSubprovider = new Subprovider(infuraProvider);
		const config = {
			...this.internalProviderConfig,
			...{
				dataSubprovider: infuraSubprovider,
				engineParams: {
					blockTrackerProvider: infuraProvider,
					pollingInterval: 12000
				}
			}
		};
		this.updateProvider(createMetamaskProvider(config));
	}
github OriginProtocol / origin-js / token / lib / ledger.js View on Github external
constructor(options, url) {
    const getTransport = () => TransportU2F.create()
    const ledger = createLedgerSubprovider(getTransport, options)

    this.engine = new ProviderEngine()
    this.engine.addProvider(ledger)
    this.engine.addProvider(new FiltersSubprovider())
    Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send
    this.engine.addProvider(new ProviderSubprovider(new Web3.providers.HttpProvider(url)))
    this.engine.start()
  }