How to use the web3-utils.toHex 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 0xbitcoin / 0xbitcoin-token / test / network-interface-helper.js View on Github external
try{
        var txCount = await web3.eth.getTransactionCount(addressFrom);
        console.log('txCount',txCount)
       } catch(error) {  //here goes if someAsyncPromise() rejected}
        console.log(error);
         return error;    //this will result in a resolved promise.
       }


    const txOptions = {
      nonce: web3Utils.toHex(txCount),
      gasLimit: web3Utils.toHex(25000),
      gasPrice: web3Utils.toHex(2e9), // 2 Gwei
      to: addressTo,
      from: addressFrom,
      value: web3Utils.toHex(web3Utils.toWei('123', 'wei'))
    //  value: web3Utils.toHex(web3Utils.toWei('123', 'wei'))
    }

    // fire away!

    console.log('fire away ')
    await this.sendSignedRawTransaction(web3,txOptions,addressFrom,account, function(err, result) {
      if (err) return console.log('error', err)
      console.log('sent', result)
    })



  },
github status-im / ens-usernames / test / enssubdomainregistry.spec.js View on Github external
it('should not slash valid subdomain', async () => {
      let subdomain = 'legituser';
      let subdomainHash = namehash.hash(subdomain + '.' + domains.free.name);
      let registrant = accountsArr[1];
      await ENSSubdomainRegistry.methods.register(
        web3Utils.sha3(subdomain),
        domains.free.namehash,
        utils.zeroAddress,
        utils.zeroBytes32,
        utils.zeroBytes32
      ).send({from: registrant});    
      let failed;
      try{
        await ENSSubdomainRegistry.methods.slashInvalidSubdomain(web3Utils.toHex(subdomain), domains.free.namehash, 4).send()
        failed = false;
      } catch(e){
        failed = true;
      }
      assert(failed, "Was slashed anyway");
    });
  });
github VolcaTech / eth2-app / test / e2pEscrow.js View on Github external
const sendTransfer = async (gasPrice, verificationAddress) => {
	if (!gasPrice) {
	    gasPrice = GAS_PRICE;
	}
	if (!verificationAddress) {
	    verificationAddress = Web3Utils.randomHex(20);
	}
	
	const txData = await escrowContract.deposit(Web3Utils.toHex(verificationAddress), {from: senderAddress, value: oneEth, gasPrice: gasPrice});
	const rawTransfer = await escrowContract.getTransfer.call(verificationAddress, {from: senderAddress});
	return parseTransfer(rawTransfer);	
    };
github 0xbitcoin / tokenpool / lib / util / transaction-helper.js View on Github external
console.log('txData',txData);

    console.log('addressFrom',addressFrom);
    console.log('addressTo',addressTo);



    if( estimatedGasCost > max_gas_cost){
      console.log("Gas estimate too high!  Something went wrong ")
      return;
    }


    const txOptions = {
      nonce: web3utils.toHex(txCount),
      gas: web3utils.toHex(estimatedGasCost),
      gasPrice: web3utils.toHex(web3utils.toWei(poolConfig.solutionGasPriceWei.toString(), 'gwei') ),
      value: 0,
      to: addressTo,
      from: addressFrom,
      data: txData
    }

    var privateKey =  this.getMintingAccount().privateKey;

  return new Promise(function (result,error) {

       this.sendSignedRawTransaction(this.web3,txOptions,addressFrom,privateKey, function(err, res) {
        if (err) error(err)
          result(res)
      })
github peppersec / erc20faucet / front / store / token.js View on Github external
async mintTokens({ state, getters, rootState, rootGetters, dispatch, commit }, { to, amount }) {
    amount = amount.toString()
    const gasPrice = rootState.metamask.gasPrice.standard
    const { tokenInstance } = getters
    const { ethAccount } = rootState.metamask
    const data = tokenInstance().methods.mint(to, toWei(amount)).encodeABI()
    const gas = await tokenInstance().methods.mint(to, toWei(amount)).estimateGas()
    const callParams = {
      method: 'eth_sendTransaction',
      params: [{
        from: ethAccount,
        to: tokenInstance()._address,
        gas: numberToHex(gas + 100000),
        gasPrice: toHex(toWei(gasPrice.toString(), 'gwei')),
        value: 0,
        data
      }],
      from: ethAccount
    }
    const txHash = await dispatch('metamask/sendAsync', callParams, { root: true })
    commit('ADD_TX', txHash)
  }
}
github bitpay / bitcore / packages / crypto-wallet-core / src / transactions / eth / index.ts View on Github external
create(params: {
    recipients: Array<{ address: string; amount: string }>;
    nonce: number;
    gasPrice: number;
    data: string;
    gasLimit: number;
  }) {
    const { recipients, nonce, gasPrice, data, gasLimit } = params;
    const { address, amount } = recipients[0];
    const txData = {
      nonce: utils.toHex(nonce),
      gasLimit: utils.toHex(gasLimit),
      gasPrice: utils.toHex(gasPrice),
      to: address,
      data,
      value: utils.toHex(amount)
    };
    const rawTx = new EthereumTx(txData).serialize().toString('hex');
    return rawTx;
  }
github realitio / realitio-dapp / cli / rc_common.js View on Github external
exports.serializedValueTX = function(params, addr, val) {
    const key = this.loadKey();
	const tra = {
		gasPrice: web3_utils.toHex(params['gas_price_in_gwei'] * GWEI_TO_WEI),
		gasLimit: web3_utils.toHex(22000),
		nonce: web3_utils.toHex(params['nonce']),
		to: addr,
		value: web3_utils.toHex(val),
		chainId: config.network_id
	};

	const tx = new Tx(tra);
    tx.sign(key);

	return tx.serialize();
}
github AutarkLabs / open-enterprise / apps / projects / app / store / helpers / issues.js View on Github external
export const updateIssueDetail = async data => {
  let returnData = { ...data }
  const repoId = toHex(data.repoId)
  const issueNumber = String(data.number)
  const requestsData = await loadRequestsData({ repoId, issueNumber })
  returnData.requestsData = requestsData
  return returnData
}
github bitpay / bitcore / packages / crypto-wallet-core / src / transactions / eth / index.ts View on Github external
create(params: {
    recipients: Array<{ address: string; amount: string }>;
    nonce: number;
    gasPrice: number;
    data: string;
    gasLimit: number;
  }) {
    const { recipients, nonce, gasPrice, data, gasLimit } = params;
    const { address, amount } = recipients[0];
    const txData = {
      nonce: utils.toHex(nonce),
      gasLimit: utils.toHex(gasLimit),
      gasPrice: utils.toHex(gasPrice),
      to: address,
      data,
      value: utils.toHex(amount)
    };
    const rawTx = new EthereumTx(txData).serialize().toString('hex');
    return rawTx;
  }
github realitio / realitio-dapp / cli / rc_common.js View on Github external
exports.serializedTX = function(params, cntr, data) {
    const key = this.loadKey();
	const tra = {
		gasPrice: web3_utils.toHex(params['gas_price_in_gwei'] * GWEI_TO_WEI),
		gasLimit: web3_utils.toHex(config.gas_limit),
		data: data,
		nonce: web3_utils.toHex(params['nonce']),
		to: cntr.address,
		value: '0x00',
		data: data,
		chainId: config.network_id
	};

	const tx = new Tx(tra);
    tx.sign(key);

	return tx.serialize();
}