How to use the @liquality/ethereum-utils.ensure0x function in @liquality/ethereum-utils

To help you get started, we’ve selected a few @liquality/ethereum-utils 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 liquality / chainabstractionlayer / packages / ethereum-erc20-provider / lib / EthereumErc20Provider.js View on Github external
async sendTransaction (to, value, data, from) {
    await this.assertContractExists()

    if (!data) {
      // erc20 transfer
      data = this.generateErc20Transfer(to, value)
      value = 0
      to = ensure0x(this._contractAddress)
    }

    return this.getMethod('sendTransaction')(to, value, data, from)
  }
github liquality / chainabstractionlayer / packages / ethereum-rpc-wallet-provider / lib / EthereumRPCWalletProvider.js View on Github external
if (from == null) {
      const addresses = await this.getAddresses()
      from = ensure0x(addresses[0].address)
    }

    value = BigNumber(value).toString(16)

    const nonce = (parseInt((await this.getMethod('jsonrpc')('eth_getTransactionCount', this.wallet.getAddressString(), 'pending')), 16)).toString(16)
    console.log('nonce')
    console.log(nonce)
    const gasPrice = await this.getMethod('jsonrpc')('eth_gasPrice')
    const gasLimit = await this.getMethod('jsonrpc')('eth_estimateGas', { from, to, value: ensure0x(value), data: ensure0x(data), gasPrice: ensure0x(gasPrice)})

    const txParams = {
      nonce: ensure0x(nonce),
      gasPrice: ensure0x(gasPrice),
      gasLimit: ensure0x(gasLimit),
      to,
      value: ensure0x(value),
      data: ensure0x(data),
      chainId: networkId
    }

    const tx = new EthereumTx(txParams)
    tx.sign(this.wallet.getPrivateKey())
    const serializedTx = tx.serialize()

    const txHash = await this.getMethod('jsonrpc')('eth_sendRawTransaction', ensure0x(serializedTx.toString('hex')))
    return remove0x(txHash)
  }
github liquality / chainabstractionlayer / packages / ethereum-rpc-wallet-provider / lib / EthereumRPCWalletProvider.js View on Github external
if (to != null) {
      to = ensure0x(to)
    }

    if (from == null) {
      const addresses = await this.getAddresses()
      from = ensure0x(addresses[0].address)
    }

    value = BigNumber(value).toString(16)

    const nonce = (parseInt((await this.getMethod('jsonrpc')('eth_getTransactionCount', this.wallet.getAddressString(), 'pending')), 16)).toString(16)
    console.log('nonce')
    console.log(nonce)
    const gasPrice = await this.getMethod('jsonrpc')('eth_gasPrice')
    const gasLimit = await this.getMethod('jsonrpc')('eth_estimateGas', { from, to, value: ensure0x(value), data: ensure0x(data), gasPrice: ensure0x(gasPrice)})

    const txParams = {
      nonce: ensure0x(nonce),
      gasPrice: ensure0x(gasPrice),
      gasLimit: ensure0x(gasLimit),
      to,
      value: ensure0x(value),
      data: ensure0x(data),
      chainId: networkId
    }

    const tx = new EthereumTx(txParams)
    tx.sign(this.wallet.getPrivateKey())
    const serializedTx = tx.serialize()

    const txHash = await this.getMethod('jsonrpc')('eth_sendRawTransaction', ensure0x(serializedTx.toString('hex')))
github liquality / chainabstractionlayer / packages / ethereum-metamask-provider / lib / EthereumMetaMaskProvider.js View on Github external
async sendTransaction (to, value, data, from) {
    const networkId = await this.getWalletNetworkId()

    if (this._network) {
      if (networkId !== this._network.networkId) {
        throw new Error('Invalid MetaMask Network')
      }
    }

    if (!from) {
      const addresses = await this.getAddresses()
      from = addressToString(addresses[0])
    }

    const tx = {
      from: ensure0x(from),
      value: ensure0x(BigNumber(value).toString(16))
    }

    if (to) tx.to = ensure0x(addressToString(to))
    if (data) tx.data = ensure0x(data)

    const txHash = await this.metamask('eth_sendTransaction', tx)

    return remove0x(txHash)
  }
github liquality / chainabstractionlayer / packages / ethereum-rpc-provider / lib / EthereumRpcProvider.js View on Github external
async sendTransaction (to, value, data, from) {
    if (!from) {
      const addresses = await this.getAddresses()
      from = addresses[0]
    }

    const tx = {
      from: ensure0x(addressToString(from)),
      to: to ? ensure0x(addressToString(from)) : null,
      value: ensure0x(BigNumber(value).toString(16))
    }

    if (to) tx.to = ensure0x(addressToString(to))
    if (data) {
      tx.data = ensure0x(data)
      tx.gas = ensure0x((await this.estimateGas(tx)).toString(16))
    }

    const txHash = await this.jsonrpc('eth_sendTransaction', tx)

    return remove0x(txHash)
  }
github liquality / chainabstractionlayer / packages / ethereum-erc20-provider / lib / EthereumErc20Provider.js View on Github external
addresses.map(address => this.getMethod('jsonrpc')(
        'eth_call',
        {
          data: [
            SOL_BALACE_OF_FUNCTION,
            padHexStart(remove0x(address), 64)
          ].join('').toLowerCase(),
          to: ensure0x(this._contractAddress).toLowerCase()
        },
        'latest'
      ))
    )
github liquality / chainabstractionlayer / packages / ethereum-erc20-loan-provider / lib / EthereumERC20LoanProvider.js View on Github external
async getBorrowerPubKey (contractAddress, block) {
    const prefixFunctionSignature = '0xac6bd7e4'
    const suffixFunctionSignature = '0x527a438f'
    const prefixBorrowerPubKey = await this.getMethod('jsonrpc')('eth_call', { data: prefixFunctionSignature, to: ensure0x(contractAddress) }, ensureBlockFormat(block))
    const suffixBorrowerPubKey = await this.getMethod('jsonrpc')('eth_call', { data: suffixFunctionSignature, to: ensure0x(contractAddress) }, ensureBlockFormat(block))
    return padHexStart(parseInt(prefixBorrowerPubKey, 16).toString(16)) + suffixBorrowerPubKey
  }
github liquality / chainabstractionlayer / packages / ethereum-erc20-loan-fund-provider / lib / EthereumERC20LoanFundProvider.js View on Github external
async getLenderPubKey (contractAddress) {
    const prefixFunctionSignature = '0xac6bd7e4'
    const suffixFunctionSignature = '0x527a438f'
    const prefixLenderPubKey = await this.getMethod('jsonrpc')('eth_call', { data: prefixFunctionSignature, to: ensure0x(contractAddress) }, 'latest')
    const suffixLenderPubKey = await this.getMethod('jsonrpc')('eth_call', { data: suffixFunctionSignature, to: ensure0x(contractAddress) }, 'latest')
    return padHexStart(parseInt(prefixLenderPubKey, 16).toString(16)) + suffixLenderPubKey
  }

@liquality/ethereum-utils

[![Build Status](https://travis-ci.com/liquality/chainabstractionlayer.svg?branch=master)](https://travis-ci.com/liquality/chainabstractionlayer) [![Coverage Status](https://coveralls.io/repos/github/liquality/chainabstractionlayer/badge.svg?branch=master

MIT
Latest version published 2 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages