ethers#getDefaultProvider TypeScript Examples

The following examples show how to use ethers#getDefaultProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx    From useDApp with MIT License 6 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: process.env.MAINNET_URL || getDefaultProvider('mainnet'),
    [Ropsten.chainId]: getDefaultProvider('ropsten'),
    [Kovan.chainId]: getDefaultProvider('kovan'),
    [Arbitrum.chainId]: 'https://arb1.arbitrum.io/rpc',
  },
  multicallVersion: 2 as const,
  fastMulticallEncoding: true,
  noMetamaskDeactivate: true,
}
Example #2
Source File: ConnectingToNetwork.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #3
Source File: EthBalance.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #4
Source File: GettingStarted.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #5
Source File: Multichain.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
    [Arbitrum.chainId]: 'https://arb1.arbitrum.io/rpc',
    [ZkSyncTestnet.chainId]: 'https://zksync2-testnet.zksync.dev',
  },
}
Example #6
Source File: ReadingWithoutWallet.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #7
Source File: SendTransaction.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
  bufferGasLimitPercentage: 10, // The percentage by which the transaction may exceed the estimated gas limit.
}
Example #8
Source File: Siwe.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #9
Source File: SwitchingNetworks.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
    [Rinkeby.chainId]: getDefaultProvider('rinkeby'),
  },
}
Example #10
Source File: TokenBalance.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #11
Source File: WalletConnectExample.tsx    From useDApp with MIT License 5 votes vote down vote up
config: Config = {
  readOnlyChainId: Mainnet.chainId,
  readOnlyUrls: {
    [Mainnet.chainId]: getDefaultProvider('mainnet'),
  },
}
Example #12
Source File: eth.ts    From coin-wallets with Apache License 2.0 5 votes vote down vote up
function getProvider(chain: 'ETH' | 'ETC' = 'ETH'): providers.BaseProvider {
  const provider =
    chain === 'ETH'
      ? getDefaultProvider()
      : new providers.JsonRpcProvider('https://www.ethercluster.com/etc', 'classic');
  return provider;
}
Example #13
Source File: fetcher.test.tsx    From ether-swr with MIT License 4 votes vote down vote up
describe('ethFetcher', () => {
  let signer: Wallet
  let provider: providers.BaseProvider

  beforeAll(() => {
    jest.setTimeout(20000)
  })

  afterAll(() => {
    jest.setTimeout(5000)
  })

  beforeEach(() => {
    provider = getDefaultProvider()
    signer = new Wallet(
      'd5dccc2af4ba994df9e79a7522051f3121150ca9c08a27d2aa17dad59c761747',
      provider
    )
    expect(signer.address).toEqual('0xbb4C771e8d880b05321ad3936597DF484b2d1b5d')
  })
  it('is defined', () => {
    expect(etherJsFetcher).toBeDefined()
  })

  it('return a fetcher', () => {
    expect(etherJsFetcher(provider)).toBeDefined()
  })

  describe('eth', () => {
    it('return the balance ', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider)
      // SWR spreads txhe array when it invoke the fetcher
      await expect(fetcher(...['getBalance', signer.address])).resolves.toEqual(
        balance
      )
    })
    it('returns multiple balances', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider)
      // SWR spreads the array when it invoke the fetcher
      await expect(
        fetcher(JSON.stringify([['getBalance', signer.address]]))
      ).resolves.toEqual([balance])
    })
  })

  describe('contract', () => {
    it('return the value', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider, ABIs)
      // SWR spreads the array when it invoke the fetcher
      await expect(
        fetcher(...[DAI_CONTRACT, 'balanceOf', signer.address])
      ).resolves.toEqual(balance)
    })

    it('return the value from a specific block', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider, ABIs)
      // SWR spreads the array when it invoke the fetcher
      await expect(
        fetcher(
          ...[DAI_CONTRACT, 'balanceOf', signer.address, { blockTag: 13589470 }]
        )
      ).resolves.toEqual(balance)
    })

    it('return multiple values', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider, ABIs)
      // SWR spreads the array when it invoke the fetcher
      await expect(
        fetcher(JSON.stringify([[DAI_CONTRACT, 'balanceOf', signer.address]]))
      ).resolves.toEqual([balance])
    })

    it('return multiple values from a specific block', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider, ABIs)
      // SWR spreads the array when it invoke the fetcher
      await expect(
        fetcher(
          JSON.stringify([
            [DAI_CONTRACT, 'balanceOf', signer.address, { blockTag: 13589470 }]
          ])
        )
      ).resolves.toEqual([balance])
    })

    it('return multiple values from different blocks', async () => {
      const balance = BigNumber.from(0)
      const fetcher = etherJsFetcher(provider, ABIs)
      // SWR spreads the array when it invoke the fetcher
      await expect(
        fetcher(
          JSON.stringify([
            [DAI_CONTRACT, 'balanceOf', signer.address, { blockTag: 13589470 }],
            [USDC_CONTRACT, 'balanceOf', signer.address, { blockTag: 13589469 }]
          ])
        )
      ).resolves.toEqual([balance, balance])
    })
  })
})