How to use the web3-utils.hexToNumber function in web3-utils

To help you get started, we’ve selected a few web3-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 floating / frame / main / clients / EthereumClient / index.js View on Github external
// Check using JSON RPC method 'eth_blockNumber'
    if (blockNumber === 0) state = 'syncing'

    // Check if block number has changed since last time Frame was running
    else if (blockNumber === this.initialBlockNumber) state = 'syncing'

    // Check using JSON RPC method 'net_peerCount'
    else if (await this._getPeerCount() === 0) state = 'syncing'

    // Check using JSON RPC method 'eth_syncing'
    else {
      const result = await this._isSyncing()
      if (!result) {
        state = 'ready'
      } else {
        store.updateClient(this.name, 'currentBlock', hexToNumber(result.currentBlock))
        store.updateClient(this.name, 'highestBlock', hexToNumber(result.highestBlock))
        state = 'syncing'
      }
    }

    // If state has changed -> log and emit new state
    if (state !== store(`main.clients.${this.name}.state`)) {
      log.info(`${this.name}:`, state)
      this.emit('state', state)
    }
  }
github floating / frame / main / clients / EthereumClient / index.js View on Github external
if (blockNumber === 0) state = 'syncing'

    // Check if block number has changed since last time Frame was running
    else if (blockNumber === this.initialBlockNumber) state = 'syncing'

    // Check using JSON RPC method 'net_peerCount'
    else if (await this._getPeerCount() === 0) state = 'syncing'

    // Check using JSON RPC method 'eth_syncing'
    else {
      const result = await this._isSyncing()
      if (!result) {
        state = 'ready'
      } else {
        store.updateClient(this.name, 'currentBlock', hexToNumber(result.currentBlock))
        store.updateClient(this.name, 'highestBlock', hexToNumber(result.highestBlock))
        state = 'syncing'
      }
    }

    // If state has changed -> log and emit new state
    if (state !== store(`main.clients.${this.name}.state`)) {
      log.info(`${this.name}:`, state)
      this.emit('state', state)
    }
  }
github poanetwork / tokenbridge-contracts / deploy / src / amb_erc677_to_erc677 / initialize.js View on Github external
[executionDailyLimit, executionMaxPerTx],
      requestGasLimit,
      foreignToHomeDecimalShift,
      owner
    )
    .encodeABI()
  const txInitialize = await sendRawTx({
    data: initializeData,
    nonce,
    to: address,
    privateKey: deploymentPrivateKey,
    url
  })

  if (txInitialize.status) {
    assert.strictEqual(Web3Utils.hexToNumber(txInitialize.status), 1, 'Transaction Failed')
  } else {
    await assertStateWithRetry(contract.methods.isInitialized().call, true)
  }
  nonce++

  console.log('Transferring bridge mediator proxy ownership to upgradeability admin')
  const proxy = new web3.eth.Contract(proxyAbi, address)
  await transferProxyOwnership({
    proxy,
    newOwner: upgradeableAdmin,
    nonce,
    url
  })
}
github poanetwork / tokenbridge-contracts / deploy / src / arbitrary_message / foreign.js View on Github external
})

  console.log('transferring proxy ownership to multisig for Foreign bridge Proxy contract')
  await transferProxyOwnership({
    proxy: foreignBridgeStorage,
    newOwner: FOREIGN_UPGRADEABLE_ADMIN,
    nonce,
    url: FOREIGN_RPC_URL
  })

  console.log('\nForeign Deployment Bridge completed\n')

  return {
    foreignBridge: {
      address: foreignBridgeStorage.options.address,
      deployedBlockNumber: Web3Utils.hexToNumber(foreignBridgeStorage.deployedBlockNumber)
    }
  }
}
github 0xbitcoin / tokenpool / lib / transaction-coordinator.js View on Github external
async getPacketReceiptDataFromWeb3Receipt(liveTransactionReceipt)
  {

    var mined = (liveTransactionReceipt != null  )
    var success = false

    if( mined )
    {
        success =  ((liveTransactionReceipt.status == true)
                                       || (web3utils.hexToNumber( liveTransactionReceipt.status) == 1 ))
   }

    var receiptData = {
      queued:false,
      pending:!mined,
      mined:mined,
      success:success
    }


    return receiptData;


  },
github poanetwork / tokenbridge-contracts / deploy / src / erc_to_erc / foreign.js View on Github external
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
      [HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
      FOREIGN_BRIDGE_OWNER,
      foreignToHomeDecimalShift
    )
    .encodeABI()

  const txInitializeBridge = await sendRawTxForeign({
    data: initializeFBridgeData,
    nonce,
    to: bridge.options.address,
    privateKey: deploymentPrivateKey,
    url: FOREIGN_RPC_URL
  })
  if (txInitializeBridge.status) {
    assert.strictEqual(Web3Utils.hexToNumber(txInitializeBridge.status), 1, 'Transaction Failed')
  } else {
    await assertStateWithRetry(bridge.methods.isInitialized().call, true)
  }
}
github poanetwork / tokenbridge / oracle / scripts / native_to_erc20 / sendForeign.js View on Github external
const poa20 = new web3Foreign.eth.Contract(ERC677_ABI, bridgeableTokenAddress)

  try {
    await isValidAmount(FOREIGN_MIN_AMOUNT_PER_TX, bridge)

    const foreignChainId = await sendRawTx({
      chain: 'foreign',
      params: [],
      method: 'net_version'
    })
    let nonce = await sendRawTx({
      chain: 'foreign',
      method: 'eth_getTransactionCount',
      params: [USER_ADDRESS, 'latest']
    })
    nonce = Web3Utils.hexToNumber(nonce)
    let actualSent = 0
    for (let i = 0; i < Number(NUMBER_OF_WITHDRAWALS_TO_SEND); i++) {
      const gasLimit = await poa20.methods
        .transferAndCall(COMMON_FOREIGN_BRIDGE_ADDRESS, Web3Utils.toWei(FOREIGN_MIN_AMOUNT_PER_TX), '0x')
        .estimateGas({ from: USER_ADDRESS })
      const data = await poa20.methods
        .transferAndCall(COMMON_FOREIGN_BRIDGE_ADDRESS, Web3Utils.toWei(FOREIGN_MIN_AMOUNT_PER_TX), '0x')
        .encodeABI({ from: USER_ADDRESS })
      const txHash = await sendTx({
        chain: 'foreign',
        privateKey: USER_ADDRESS_PRIVATE_KEY,
        data,
        nonce,
        gasPrice: FOREIGN_TEST_TX_GAS_PRICE,
        amount: '0',
        gasLimit,
github poanetwork / tokenbridge-contracts / deploy / src / erc_to_native / foreign.js View on Github external
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
      [HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
      FOREIGN_BRIDGE_OWNER,
      foreignToHomeDecimalShift,
      homeBridgeAddress
    )
    .encodeABI()
  const txInitializeBridge = await sendRawTxForeign({
    data: initializeFBridgeData,
    nonce,
    to: bridge.options.address,
    privateKey: deploymentPrivateKey,
    url: FOREIGN_RPC_URL
  })
  if (txInitializeBridge.status) {
    assert.strictEqual(Web3Utils.hexToNumber(txInitializeBridge.status), 1, 'Transaction Failed')
  } else {
    await assertStateWithRetry(bridge.methods.isInitialized().call, true)
  }
}
github poanetwork / tokenbridge / oracle / scripts / erc20_to_native / sendHome.js View on Github external
const bridge = new web3Home.eth.Contract(HOME_ERC_TO_NATIVE_ABI, COMMON_HOME_BRIDGE_ADDRESS)

  try {
    await isValidAmount(HOME_MIN_AMOUNT_PER_TX, bridge)

    const homeChainId = await sendRawTx({
      chain: 'home',
      params: [],
      method: 'net_version'
    })
    let nonce = await sendRawTx({
      chain: 'home',
      method: 'eth_getTransactionCount',
      params: [USER_ADDRESS, 'latest']
    })
    nonce = Web3Utils.hexToNumber(nonce)
    let actualSent = 0
    for (let i = 0; i < Number(NUMBER_OF_DEPOSITS_TO_SEND); i++) {
      const txHash = await sendTx({
        chain: 'home',
        privateKey: USER_ADDRESS_PRIVATE_KEY,
        data: '0x',
        nonce,
        gasPrice: HOME_TEST_TX_GAS_PRICE,
        amount: HOME_MIN_AMOUNT_PER_TX,
        gasLimit: 100000,
        to: COMMON_HOME_BRIDGE_ADDRESS,
        web3: web3Home,
        chainId: homeChainId
      })
      if (txHash !== undefined) {
        nonce++