How to use the web3-provider-engine/subproviders/fetch 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 loomnetwork / dashboard / src / components / modals / HardwareWalletModal.vue View on Github external
const networkId = Number(this.state.ethereum.networkId)
    const rpcUrl = this.state.ethereum.endpoint
    const engine = new ProviderEngine()
    const transport = await this.transport()
    const ledger = createLedgerSubprovider(
      () => transport, {
        networkId,
        accountsLength: 1,
        path,
      })

    ledger.signMessage = ledger.signPersonalMessage
    engine.addProvider(ledger)
    engine.addProvider(
      // new RpcSubprovider({ rpcUrl }),
      new FetchSubprovider({
        rpcUrl,
      }),
    )
    engine.start()
    // @ts-ignore
    // const web3account = (await .web3!.eth.getAccounts())[0]
    // console.assert(web3account === selectedAddress,
    //  `Expected web3 to be initialized with ${selectedAddress} but got ${web3account}`)

    // @ts-ignore
    ethereumModule.setProvider(engine)
  }
github SelfKeyFoundation / Identity-Wallet / src / main / blockchain / web3-service.js View on Github external
async switchToLedgerWallet(accountsOffset = 0, accountsQuantity = 6) {
		const engine = new ProviderEngine();
		this.getLedgerTransport = () => HWTransportNodeHid.create();
		const ledger = Web3SubProvider(this.getLedgerTransport, {
			networkId: CONFIG.chainId,
			accountsLength: accountsQuantity,
			accountsOffset: accountsOffset
		});
		const subscriptionSubprovider = new SubscriptionSubprovider();
		subscriptionSubprovider.on('data', (err, notification) => {
			engine.emit('data', err, notification);
		});

		engine.addProvider(ledger);
		engine.addProvider(subscriptionSubprovider);
		engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
		engine.start();

		this.web3 = new Web3(engine);
		this.web3.transactionConfirmationBlocks = 1;
	}
github SelfKeyFoundation / Identity-Wallet / src / main / blockchain / web3-service.js View on Github external
this.trezorWalletSubProvider = await TrezorWalletSubProviderFactory(
			CONFIG.chainId,
			accountsOffset,
			accountsQuantity,
			eventEmitter
		);
		const engine = new ProviderEngine();

		const subscriptionSubprovider = new SubscriptionSubprovider();
		subscriptionSubprovider.on('data', (err, notification) => {
			engine.emit('data', err, notification);
		});

		engine.addProvider(this.trezorWalletSubProvider);
		engine.addProvider(subscriptionSubprovider);
		engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
		engine.start();

		this.web3 = new Web3(engine);
		this.web3.transactionConfirmationBlocks = 1;
	}
github loomnetwork / dashboard / src / services / initWeb3.ts View on Github external
return new Promise(async (resolve, reject) => {
    const engine = new ProviderEngine()
    const getTransport = () => TransportU2F.create()
    const ledger = createLedgerSubprovider(getTransport, {
      networkId: 1,
      accountsLength: 5,
    })

    ledger.getAccounts = () => ["123"]

    ledger.signMessage = ledger.signPersonalMessage
    engine.addProvider(ledger)
    engine.addProvider(
      new FetchSubprovider({
        rpcUrl: "https://mainnet.infura.io/5Ic91y0T9nLh6qUg33K0",
      }),
    )
    engine.start()
    resolve(new Web3(engine))
  })
}
github dexdexplatform / dexdex-mono / packages / widget / src / model / wallets / ledger.ts View on Github external
export function getProvider() {
  const ethNet = appConfig().network;
  const networkId = appConfig().networkId;
  const rpcUrl = getNodeUrl(ethNet);

  const engine = new ProviderEngine();
  const getTransport = async () => TransportU2F.create();

  const ledger = createLedgerSubprovider(getTransport, {
    networkId,
    accountsLength: 5,
  });
  engine.addProvider(ledger);
  engine.addProvider(new FetchSubprovider({ rpcUrl }));
  engine.start();
  return engine;
}
github SelfKeyFoundation / Identity-Wallet / src / main / blockchain / leadger-service.js View on Github external
createWeb3(accountsOffset, accountsQuantity) {
		accountsOffset = accountsOffset || 0;
		accountsQuantity = accountsQuantity || 6;
		const engine = new ProviderEngine();
		const getTransport = () => HWTransportNodeHid.create();
		const ledger = Web3SubProvider(getTransport, {
			networkId: chainId,
			accountsLength: accountsQuantity,
			accountsOffset
		});

		engine.addProvider(ledger);
		engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
		engine.start();
		return new Web3(engine);
	}
	signTransaction(args) {
github SelfKeyFoundation / Identity-Wallet / src / main / blockchain / web3-service.js View on Github external
async defaultWallet() {
		const engine = new ProviderEngine();

		engine.addProvider(this.getWalletEthTxSubprovider());
		engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));

		engine.start();

		this.web3 = new Web3(engine);
		this.web3.transactionConfirmationBlocks = 1;
	}
github LedgerHQ / ledgerjs / packages / create-dapp / template / src / wallets.js View on Github external
export const getReadOnlyWeb3 = async () => {
  const engine = new ProviderEngine();
  engine.addProvider(new FetchSubprovider({ rpcUrl }));
  engine.start();
  return new Web3(engine);
};