How to use the eth-connect.toWei function in eth-connect

To help you get started, we’ve selected a few eth-connect 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 decentraland / explorer / kernel / packages / shared / ethereum / EthereumService.ts View on Github external
export async function requirePayment(toAddress: string, amount: number, currency: string): Promise {
  try {
    let fromAddress = await getUserAccount()
    if (!fromAddress) {
      throw new Error(`Not a web3 game session`)
    }

    let result: Promise

    if (currency === 'ETH') {
      result = requestManager.eth_sendTransaction({
        to: toAddress,
        from: fromAddress,
        // TODO: fix this in eth-connect
        value: toWei(amount as any, 'ether') as any,
        data: null as any
      })
    } else {
      const supportedTokens: Record = {} // a TODO: getNetworkConfigurations(network).paymentTokens

      if (currency in supportedTokens === false) {
        // tslint:disable:no-console
        console.warn(`WARNING! Using a non-supported coin. Skipping operation! Please use one of the next coins 'ETH'`)
        return false
      }

      const contractInstance = await getERC20(requestManager, supportedTokens[currency])

      // Check this account has enough tokens for the transaction
      const balance = await getERC20Balance(fromAddress, contractInstance.address)
      if (balance.lt(amount)) {

eth-connect

Ethereum TypeScript API, middleware to talk to a ethereum node using an async provider

LGPL-3.0
Latest version published 10 months ago

Package Health Score

62 / 100
Full package analysis