How to use the ethers.ethers.providers function in ethers

To help you get started, we’ve selected a few ethers 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 ConnextProject / indra / modules / daicard / src / App.js View on Github external
async componentDidMount() {
    // If no mnemonic, create one and save to local storage
    console.log(`dont worry, you're on the right branch :)`)
    let mnemonic = localStorage.getItem("mnemonic");
    if (!mnemonic) {
      mnemonic = eth.Wallet.createRandom().mnemonic;
      localStorage.setItem("mnemonic", mnemonic);
    }

    const nodeUrl = urls.nodeUrl;
    const ethProviderUrl = urls.ethProviderUrl;
    const ethprovider = new eth.providers.JsonRpcProvider(ethProviderUrl);
    const cfPath = "m/44'/60'/0'/25446";
    const cfWallet = eth.Wallet.fromMnemonic(mnemonic, cfPath).connect(ethprovider);
    const network = await ethprovider.getNetwork();

    let store;
    if (urls.pisaUrl(network.chainId)) {
      store = storeFactory({
        wallet: cfWallet,
        pisaClient: new PisaClient(
          urls.pisaUrl(network.chainId),
          "0xa4121F89a36D1908F960C2c9F057150abDb5e1E3", // TODO: Don't hardcode
        ),
      });
    } else {
      store = storeFactory();
    }
github ethers-io / ethers.js / packages / cli / lib.esm / cli.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            let runners = [];
            this.wait = argParser.consumeFlag("wait");
            this.yes = argParser.consumeFlag("yes");
            /////////////////////
            // Provider
            let network = (argParser.consumeOption("network") || "homestead");
            let providers = [];
            let rpc = [];
            argParser.consumeOptions("rpc").forEach((url) => {
                let provider = new ethers.providers.JsonRpcProvider(url);
                providers.push(provider);
                rpc.push(provider);
            });
            if (argParser.consumeFlag("alchemy")) {
                providers.push(new ethers.providers.AlchemyProvider(network));
            }
            if (argParser.consumeFlag("etherscan")) {
                providers.push(new ethers.providers.EtherscanProvider(network));
            }
            if (argParser.consumeFlag("infura")) {
                providers.push(new ethers.providers.InfuraProvider(network));
            }
            if (argParser.consumeFlag("nodesmith")) {
                providers.push(new ethers.providers.NodesmithProvider(network));
            }
            if (argParser.consumeFlag("offline")) {
                providers.push(new OfflineProvider(network));
            }
            if (providers.length === 1) {
                ethers.utils.defineReadOnly(this, "provider", providers[0]);
            }
github Uniswap / uniswap-sdk / src / data / index.ts View on Github external
async function getChainIdAndProvider(chainIdOrProvider: ChainIdOrProvider): Promise<_ChainIdAndProvider> {
  // if a chainId is provided, get a default provider for it
  if (isChainId(chainIdOrProvider)) {
    return {
      chainId: chainIdOrProvider,
      provider: ethers.getDefaultProvider(_CHAIN_ID_NAME[chainIdOrProvider])
    }
  }
  // if a provider is provided, fetch the chainId from it
  else {
    const provider: ethers.providers.Provider = isLowLevelProvider(chainIdOrProvider)
      ? new ethers.providers.Web3Provider(chainIdOrProvider)
      : chainIdOrProvider
    const { chainId }: ethers.utils.Network = await provider.getNetwork()

    if (!(chainId in SUPPORTED_CHAIN_ID)) {
      throw Error(`chainId ${chainId} is not valid.`)
    }

    return {
      chainId,
      provider
    }
  }
}
github AugurProject / augur / packages / augur-tools / src / flash / generate-ganache-seed.ts View on Github external
function makeGanacheProvider(accounts: Account[]): ethers.providers.Web3Provider {
  return new ethers.providers.Web3Provider(ganache.provider({
    accounts,
    // TODO: For some reason, our contracts here are too large even though production ones aren't. Is it from debugging or lack of flattening?
    allowUnlimitedContractSize: true,
    db,
    network_id: 123456,
    gasLimit: 75000000000,
    debug: false,
    // vmErrorsOnRPCResponse: true,
  }));
}
github MyCryptoHQ / MyCrypto / common / v2 / services / EthService / network / helpers.ts View on Github external
return new ethers.providers.EtherscanProvider(networkName);
      }
      case NodeType.WEB3: {
        const ethereumProvider = window.ethereum;
        const networkName = getValidEthscanNetworkId(id);
        return new ethers.providers.Web3Provider(ethereumProvider, networkName);
      }

      // Option to use the EthersJs InfuraProvider, but need figure out the apiAcessKey
      // https://docs.ethers.io/ethers.js/html/api-providers.html#jsonrpcprovider-inherits-from-provider
      // case NodeType.INFURA:
      //   return new ethers.providers.InfuraProvider(name);

      // default case covers the remaining NodeTypes.
      default:
        return new ethers.providers.JsonRpcProvider(url);
    }
  });
github unlock-protocol / unlock / rover / src / server.ts View on Github external
import RoverEmitter from './roverEmitter'
import { Storage } from './storage'
import transaction from './handler/transaction'
import { blockHandler } from './handler/block'

import Backfiller from './backfill'
import { Registry } from './registry'

const express = require('express')

const app = express()
config({ path: path.resolve(process.cwd(), '.env') })
let configuration = require('../config/config')

let emitter = new RoverEmitter()
let provider = new ethers.providers.JsonRpcProvider(configuration.provider_uri)
const port = configuration.serverPort

async function main(provider, emitter, configuration) {
  let connection = await createConnection(configuration)
  let storage = new Storage(connection.manager)
  let backfill = new Backfiller(configuration.network, emitter)

  provider.on('block', async blockNumber => {
    blockHandler(storage, blockNumber, emitter, provider)
  })

  emitter.on('transaction', async transactionHash => {
    transaction.transactionHandler(
      storage,
      connection,
      transactionHash,
github smartcontractkit / chainlink / evm / v0.5 / src / helpers.ts View on Github external
export function create any>(
  contractFactory: T,
  address: string,
): InstanceType {
  const web3Instance = (global as any).web3
  const provider = new ethers.providers.Web3Provider(
    web3Instance.currentProvider,
  )
  const signer = provider.getSigner(address)
  const factory = new contractFactory(signer)

  return factory
}
github streamr-dev / streamr-client-javascript / src / Signer.js View on Github external
constructor(options = {}) {
        this.options = options
        if (this.options.privateKey) {
            const wallet = new ethers.Wallet(this.options.privateKey)
            this.address = wallet.address
            this.sign = (d) => wallet.signMessage(d)
        } else if (this.options.provider) {
            const provider = new ethers.providers.Web3Provider(this.options.provider)
            const signer = provider.getSigner()
            this.address = signer.address
            this.sign = async (d) => signer.signMessage(d)
        } else {
            throw new Error('Need either "privateKey" or "provider".')
        }
    }
github ethers-io / ethers.js / packages / cli / src.ts / cli.ts View on Github external
argParser.consumeOptions("rpc").forEach((url) => {
            let provider = new ethers.providers.JsonRpcProvider(url)
            providers.push(provider);
            rpc.push(provider);
        });