How to use @liquality/ethereum-utils - 10 common examples

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-swap-provider / lib / EthereumSwapProvider.js View on Github external
createSwapScript (recipientAddress, refundAddress, secretHash, expiration) {
    recipientAddress = remove0x(addressToString(recipientAddress))
    refundAddress = remove0x(addressToString(refundAddress))

    const dataSizeBase = 112
    const redeemDestinationBase = 66
    const refundDestinationBase = 89
    const expirationHex = expiration.toString(16)
    const expirationEncoded = padHexStart(expirationHex) // Pad with 0
    const expirationSize = expirationEncoded.length / 2
    const expirationPushOpcode = (0x60 - 1 + expirationSize).toString(16)
    const redeemDestinationEncoded = (redeemDestinationBase + expirationSize).toString(16)
    const refundDestinationEncoded = (refundDestinationBase + expirationSize).toString(16)
    const dataSizeEncoded = (dataSizeBase + expirationSize).toString(16)

    return [
      // Constructor
      '60', dataSizeEncoded, // PUSH1 {dataSizeEncoded}
github liquality / chainabstractionlayer / packages / ethereum-swap-provider / lib / EthereumSwapProvider.js View on Github external
createSwapScript (recipientAddress, refundAddress, secretHash, expiration) {
    recipientAddress = remove0x(addressToString(recipientAddress))
    refundAddress = remove0x(addressToString(refundAddress))

    const dataSizeBase = 112
    const redeemDestinationBase = 66
    const refundDestinationBase = 89
    const expirationHex = expiration.toString(16)
    const expirationEncoded = padHexStart(expirationHex) // Pad with 0
    const expirationSize = expirationEncoded.length / 2
    const expirationPushOpcode = (0x60 - 1 + expirationSize).toString(16)
    const redeemDestinationEncoded = (redeemDestinationBase + expirationSize).toString(16)
    const refundDestinationEncoded = (refundDestinationBase + expirationSize).toString(16)
    const dataSizeEncoded = (dataSizeBase + expirationSize).toString(16)

    return [
      // Constructor
      '60', dataSizeEncoded, // PUSH1 {dataSizeEncoded}
      '80', // DUP1
github liquality / chainabstractionlayer / packages / ethereum-erc20-swap-provider / lib / EthereumErc20SwapProvider.js View on Github external
const refundSwapTransaction = block.transactions.find(transaction =>
      transaction.to === initiationTransaction.contractAddress &&
      transaction.input === remove0x(SOL_REFUND_FUNCTION) && // eslint-disable-line
      block.timestamp >= expiration
    )
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-loan-provider / lib / EthereumERC20LoanProvider.js View on Github external
async getBiddingExpiration (contractAddress, block) {
    const biddingExpiration = await this.getMethod('jsonrpc')('eth_call', { data: '0x9f2fe458', to: ensure0x(contractAddress) }, ensureBlockFormat(block))
    return parseInt(biddingExpiration, 16)
  }
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'
      ))
    )

@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