How to use the web3-utils.toWei 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 NovakDistributed / macroverse / test / TestMacroverseUniversalRegistry.js View on Github external
it("should prohibit revealing at the right time but with too low a deposit", async function() {
    let instance = await MacroverseUniversalRegistry.deployed()
    let backend = await MacroverseRealEstate.deployed()

    // Remember our commitment from the last test?
    let to_claim = mv.keypathToToken('0.0.0.0')
    let nonce = 0xDEAD
    
    assert.equal(await backend.exists(to_claim), false, "Token exists too early")

    // We're also going to test price adjustments

    let since = web3.eth.getBlock('latest').number

    // Adjust the price up
    await instance.setMinimumSystemDeposit(Web3Utils.toWei("1001", "ether"))

    let saw_event = false
    let new_price = undefined
    for (let event_report of await instance.getPastEvents('DepositScaleChange', {fromBlock: since})) {
      if (event_report.event == 'DepositScaleChange') {
        // Remember we saw the change
        saw_event = true
        // And what we changed to
        new_price = event_report.args.new_min_system_deposit_in_atomic_units
      }
    }

    assert.equal(saw_event, true, "We got the first expected price change event")
    assert.equal(new_price, Web3Utils.toWei("1001", "ether"), "We got the first expected new price")

    await assert_throws(instance.reveal(to_claim, nonce), "Revealed with too small deposit")
github enigmampc / secret-contracts / enigma-lib / test-utils.js View on Github external
register () {
        //***** Simulating the principal node
        console.log ('registering principal', this.custodian);
        const report = engUtils.encodeReport (
            this.params[1],
            this.params[2],
            this.params[3],
        );
        // Using the same artificial data for all workers
        return this.contract.register (
            this.params[0], report, {
                from: this.custodian,
                gas: 4712388,
                gasPrice: web3Utils.toWei (GAS_PRICE_GWEI, 'gwei')
            }
        );
    }
github NovakDistributed / macroverse / test / TestMacroverseUniversalRegistry.js View on Github external
it("should prohibit revealing for a parent token of owned land", async function() {
    let instance = await MacroverseUniversalRegistry.deployed()
    let mrv = await MRVToken.deployed()

    // Approve the deposit tokens
    await mrv.approve(instance.address, await mrv.balanceOf.call(accounts[1]), {from: accounts[1]})

    // This is a parent of the land token we have been working with
    let to_claim = mv.keypathToToken('0.0.0.0.0.-1.7.2.2')
    let nonce = 0xDEADBEEF88
    let data_hash = mv.hashTokenAndNonce(to_claim, nonce)

    // Commit for it
    await instance.commit(data_hash, Web3Utils.toWei("1000", "ether"), {from: accounts[1]})

    // Advance time for 10 minutes to mature the commitment
    await mv.advanceTime(10)

    // Now try revealing. It should fail.
    await assert_throws(instance.reveal(to_claim, nonce), "Revealed land superplot")

    // Clean up
    await instance.cancel(data_hash, {from: accounts[1]})
  })
github tornadocash / tornado-core / migrationDeposits.js View on Github external
async function migrateState({ subtrees, lastRoot, commitments, nullifiers, newInstance }) {
  const loadBy = 100
  let commitmentsToLoad
  let nullifiersToLoad
  await newInstance.methods.initializeTreeForMigration(subtrees, lastRoot).send({
    gas: numberToHex(2500000),
    gasPrice: toHex(toWei('12', 'gwei')),
    from: web3Target.eth.defaultAccount
  })
  for(let i=0; i < commitments.length / loadBy; i++) {
    commitmentsToLoad = commitments.slice(i*loadBy, (i+1)*loadBy)
    nullifiersToLoad = nullifiers.slice(i*loadBy, (i+1)*loadBy)
    console.log(`Uploading commitments and nullifiers from ${i*loadBy} to ${(i+1)*loadBy}:`)
    // console.log('Commitments:\n', commitmentsToLoad)
    // console.log('Nullifiers:\n', nullifiersToLoad)

    const tx = await newInstance.methods.migrateState(
      commitmentsToLoad,
      nullifiersToLoad
    ).send({
      gas: numberToHex(6500000),
      gasPrice: toHex(toWei('12', 'gwei')),
      from: web3Target.eth.defaultAccount
github urbit / bridge / src / lib / useEthereumTransaction.js View on Github external
const broadcast = useCallback(async () => {
    try {
      setConfirmationProgress(0.0);
      setError(undefined);

      const rawTxs = signedTransactions.map(stx => hexify(stx.serialize()));

      const costGwei = toBN(gasLimit)
        .mul(toBN(gasPrice))
        .mul(toBN(rawTxs.length));
      const cost = toWei(costGwei.toString(), 'gwei');
      let usedTank = false;
      // if this ethereum transaction is being executed by a specific point
      // see if we can use the tank
      if (Just.hasInstance(pointCursor)) {
        usedTank = await ensureFundsFor(
          _web3,
          pointCursor.value,
          _wallet.address,
          cost,
          rawTxs,
          (address, minBalance, balance) =>
            setNeedFunds({ address, minBalance, balance }),
          () => setNeedFunds(undefined)
        );
      }
github NovakDistributed / macroverse / test / TestMacroverseUniversalRegistry.js View on Github external
it("should allow canceling your own commitment that you failed to reveal", async function() {
    let instance = await MacroverseUniversalRegistry.deployed()
    let mrv = await MRVToken.deployed()

    let to_claim = mv.keypathToToken('0.0.0.0')
    let nonce = 0xDEAD2 
    let data_hash = mv.hashTokenAndNonce(to_claim, nonce)

    await instance.cancel(data_hash)

    assert.ok(true, "Cancel transaction goes through")

    assert.equal((await mrv.balanceOf.call(accounts[0])), Web3Utils.toWei("4000", "ether"), "Our deposit was refunded")
    
  })
github rstormsf / multisender / src / stores / txStore.js View on Github external
try {
      let encodedData = await multisender.methods.multisendToken(token_address, addresses_to_send, balances_to_send).encodeABI({from: this.web3Store.defaultAccount})
      let gas = await web3.eth.estimateGas({
          from: this.web3Store.defaultAccount,
          data: encodedData,
          value: Web3Utils.toHex(Web3Utils.toWei(ethValue.toString())),
          to: proxyMultiSenderAddress
      })
      console.log('gas', gas)
      let tx = multisender.methods.multisendToken(token_address, addresses_to_send, balances_to_send)
      .send({
        from: this.web3Store.defaultAccount,
        gasPrice: this.gasPriceStore.standardInHex,
        gas: Web3Utils.toHex(gas + 150000),
        value: Web3Utils.toHex(Web3Utils.toWei(ethValue.toString())),
      })

      .on('transactionHash', (hash) => {
        this.txHashToIndex[hash] = this.txs.length
        this.txs.push({status: 'pending', name: `Sending Batch #${this.txs.length} ${this.tokenStore.tokenSymbol}\n
          From ${addresses_to_send[0]} to: ${addresses_to_send[addresses_to_send.length-1]}
        `, hash})
        this.getTxStatus(hash)
      })
      .on('error', (error) => {
        swal("Error!", error.message, 'error')
        console.log(error)
      })
      slice--;
      if (slice > 0) {
        this._multisend({slice, addPerTx});
github Distense / distense / src / features / user / gasPrices.js View on Github external
import web3Utils from 'web3-utils'

export const TESTNET_GAS_PRICE = web3Utils.toWei('25', 'gwei')
export const MAINNET_GAS_PRICE = web3Utils.toWei('1', 'gwei')
github poanetwork / tokenbridge / oracle / scripts / erc20_to_erc20 / sendHome.js View on Github external
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_WITHDRAWALS_TO_SEND); i++) {
      const gasLimit = await erc677.methods
        .transferAndCall(COMMON_HOME_BRIDGE_ADDRESS, Web3Utils.toWei(HOME_MIN_AMOUNT_PER_TX), '0x')
        .estimateGas({ from: USER_ADDRESS })
      const data = await erc677.methods
        .transferAndCall(COMMON_HOME_BRIDGE_ADDRESS, Web3Utils.toWei(HOME_MIN_AMOUNT_PER_TX), '0x')
        .encodeABI({ from: USER_ADDRESS })
      const txHash = await sendTx({
        chain: 'home',
        privateKey: USER_ADDRESS_PRIVATE_KEY,
        data,
        nonce,
        gasPrice: HOME_TEST_TX_GAS_PRICE,
        amount: '0',
        gasLimit,
        to: BRIDGEABLE_TOKEN_ADDRESS,
        web3: web3Home,
        chainId: homeChainId
      })