How to use the eth-provider function in eth-provider

To help you get started, we’ve selected a few eth-provider 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 pandonetwork / pando / packages / git-remote-pando / src / helper.ts View on Github external
private async _ethConnect(): Promise {
    this.debug('connecting to gateway', this.config.ethereum.gateway)

    const provider = ETHProvider(this.config.ethereum.gateway)
    const spinner = ora('Connecting to Ethereum').start()

    while (true) {
      try {
        const accounts = await provider.send('eth_accounts')
        spinner.stop()
        for (const account of accounts) {
          if (account === this.config.ethereum.account) return provider
        }
        this._die("Failed to access your Ethereum account. Update your gateway configuration or run 'git pando config' to select another account.")
      } catch (err) {
        if (err.code === 4100 || err.code === 4001) {
          spinner.text = `Error connecting to Ethereum. ${err.message}.`
          await _timeout(2000)
        } else {
          spinner.stop()
github pandonetwork / pando / packages / git-pando / src / commands / config / questions.ts View on Github external
export default async (): Promise => {
  const configuration = {
    ethereum: {
      account: undefined as any,
      gateway: undefined as any,
    },
    ipfs: {
      gateway: undefined as any,
    },
  }

  const type = (await inquirer.prompt(questions.ethereum.type)).result
  configuration.ethereum.gateway = type === 'Frame' ? FRAME_ENDPOINT : (await inquirer.prompt(questions.ethereum.gateway)).result

  const provider = ETHProvider(configuration.ethereum.gateway)
  const message = type === 'Frame' ? 'Connecting to Frame' : 'Connecting to Ethereum gateway'
  const spinner = ora(message).start()

  while (true) {
    try {
      const accounts = await provider.send('eth_accounts')
      spinner.stop()
      configuration.ethereum.account = (await inquirer.prompt(await questions.ethereum.account(accounts))).result
      break
    } catch (err) {
      spinner.text = message + ': ' + err.message
      await _timeout(2000)
    }
  }

  configuration.ipfs.gateway = (await inquirer.prompt(questions.ipfs.gateway)).result
github pandonetwork / pando / packages / git-pando / src / lib / pando.ts View on Github external
private static async _provider(options: IPandoOptions): Promise {
    const provider = ETHProvider(options.ethereum.gateway)
    const spinner = ora('Connecting to Ethereum').start()

    while (true) {
      try {
        const accounts = await provider.send('eth_accounts')
        spinner.stop()
        for (const account of accounts) {
          if (account === options.ethereum.account) return provider
        }
        die("Failed to access your Ethereum account. Update your gateway configuration or run 'git pando config' to select another account.")
      } catch (err) {
        if (err.code === 4100 || err.code === 4001) {
          spinner.text = `Error connecting to Ethereum. ${err.message}.`
          await _timeout(2000)
        } else {
          spinner.stop()
github NoahZinsmeister / web3-react / packages / frame-connector / src / index.ts View on Github external
public async activate(): Promise {
    if (!this.provider) {
      this.provider = ethProvider('frame')
    }

    this.provider
      .on('networkChanged', this.handleNetworkChanged)
      .on('chainChanged', this.handleChainChanged)
      .on('accountsChanged', this.handleAccountsChanged)
      .on('close', this.handleClose)

    const account = await this.provider
      .enable()
      .then((accounts: string[]): string => accounts[0])
      .catch((error: Error): void => {
        if (error && (error as any).code === 4001) {
          throw new UserRejectedRequestError()
        } else {
          throw error

eth-provider

A Universal Ethereum Provider

GPL-3.0
Latest version published 2 months ago

Package Health Score

69 / 100
Full package analysis

Popular eth-provider functions

Similar packages