How to use the ethereumjs-util.addHexPrefix function in ethereumjs-util

To help you get started, we’ve selected a few ethereumjs-util 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 MetaMask / web3-provider-engine / subproviders / vm.js View on Github external
if (self.opts.debug) {
    vm.on('step', function (data) {
      console.log(data.opcode.name)
    })
  }

  // create tx
  var txParams = payload.params[0]
  // console.log('params:', payload.params)

  const normalizedTxParams = {
    to: txParams.to ? ethUtil.addHexPrefix(txParams.to) : undefined,
    from: txParams.from ? ethUtil.addHexPrefix(txParams.from) : undefined,
    value: txParams.value ? ethUtil.addHexPrefix(txParams.value) : undefined,
    data: txParams.data ? ethUtil.addHexPrefix(txParams.data) : undefined,
    gasLimit: txParams.gas ? ethUtil.addHexPrefix(txParams.gas) : block.header.gasLimit,
    gasPrice: txParams.gasPrice ? ethUtil.addHexPrefix(txParams.gasPrice) : undefined,
    nonce: txParams.nonce ? ethUtil.addHexPrefix(txParams.nonce) : undefined,
  }
  var tx = new FakeTransaction(normalizedTxParams)
  tx._from = normalizedTxParams.from || '0x0000000000000000000000000000000000000000'

  vm.runTx({
    tx: tx,
    block: block,
    skipNonce: true,
    skipBalance: true
  }, function(err, results) {
    if (err) return cb(err)
    if (results.error != null) {
      return cb(new Error("VM error: " + results.error))
    }
github MetaMask / web3-provider-engine / subproviders / vm.js View on Github external
enableHomestead: true
  })

  if (self.opts.debug) {
    vm.on('step', function (data) {
      console.log(data.opcode.name)
    })
  }

  // create tx
  var txParams = payload.params[0]
  // console.log('params:', payload.params)

  const normalizedTxParams = {
    to: txParams.to ? ethUtil.addHexPrefix(txParams.to) : undefined,
    from: txParams.from ? ethUtil.addHexPrefix(txParams.from) : undefined,
    value: txParams.value ? ethUtil.addHexPrefix(txParams.value) : undefined,
    data: txParams.data ? ethUtil.addHexPrefix(txParams.data) : undefined,
    gasLimit: txParams.gas ? ethUtil.addHexPrefix(txParams.gas) : block.header.gasLimit,
    gasPrice: txParams.gasPrice ? ethUtil.addHexPrefix(txParams.gasPrice) : undefined,
    nonce: txParams.nonce ? ethUtil.addHexPrefix(txParams.nonce) : undefined,
  }
  var tx = new FakeTransaction(normalizedTxParams)
  tx._from = normalizedTxParams.from || '0x0000000000000000000000000000000000000000'

  vm.runTx({
    tx: tx,
    block: block,
    skipNonce: true,
    skipBalance: true
  }, function(err, results) {
    if (err) return cb(err)
github opporty-com / Plasma-Cash / client / routing / txTestController.js View on Github external
async createTransactionsFromUTXO() {
        this.utxos = await getAllUtxosWithKeys();
        this.alltransactions = [];

        for (let i in this.utxos) {
            let utxo = this.utxos[i];
            let blockNumber = parseInt(i.split('_')[1]);

            try {
                let txData = {
                    prev_hash: utxo.getHash().toString('hex'),
                    prev_block: blockNumber,
                    token_id: utxo.token_id.toString(),
                    new_owner: this.nextAddressGen.next(utxo.new_owner).value
                };
                let txDataForRlp = [ethUtil.addHexPrefix(txData.prev_hash), txData.prev_block, ethUtil.toBuffer(txData.token_id), txData.new_owner];
                let txRlpEncoded = ethUtil.hashPersonalMessage(ethUtil.sha3(RLP.encode(txDataForRlp)));

                if (utxo.new_owner instanceof Buffer)
                    utxo.new_owner = ethUtil.addHexPrefix(utxo.new_owner.toString('hex')).toLowerCase();

                let signature = ethUtil.ecsign(txRlpEncoded, prkeys[utxo.new_owner]);

                txData.signature = ethUtil.toRpcSig(signature.v, signature.r, signature.s).toString("hex");
                let createdTx = createSignedTransaction(txData);
                this.alltransactions.push(createdTx);
            } catch (e) {
                console.log(e);
            }
        }

        console.log('TXcount - ', this.alltransactions.length);
github brave / ethereum-remote-client / ui / app / components / app / customize-gas-modal / index.js View on Github external
)
    updateSendAmount(maxAmount)
  }

  metricsEvent({
    eventOpts: {
      category: 'Activation',
      action: 'userCloses',
      name: 'closeCustomizeGas',
    },
    pageOpts: {
      section: 'customizeGasModal',
      component: 'customizeGasSaveButton',
    },
    customVariables: {
      gasPriceChange: (new BigNumber(ethUtil.addHexPrefix(gasPrice))).minus(new BigNumber(ethUtil.addHexPrefix(originalState.gasPrice))).toString(10),
      gasLimitChange: (new BigNumber(ethUtil.addHexPrefix(gasLimit))).minus(new BigNumber(ethUtil.addHexPrefix(originalState.gasLimit))).toString(10),
    },
  })

  setGasPrice(ethUtil.addHexPrefix(gasPrice))
  setGasLimit(ethUtil.addHexPrefix(gasLimit))
  setGasTotal(ethUtil.addHexPrefix(gasTotal))
  updateSendErrors({ insufficientFunds: false })
  hideModal()
}
github MyCryptoHQ / MyCrypto / common / v2 / services / EthService / utils / signing.ts View on Github external
export function signMessageWithPrivKeyV2(privKey: Buffer, msg: string): string {
  const hash = hashPersonalMessage(toBuffer(msg));
  const signed = ecsign(hash, privKey);
  const combined = Buffer.concat([
    Buffer.from(signed.r),
    Buffer.from(signed.s),
    Buffer.from([signed.v])
  ]);
  const combinedHex = combined.toString('hex');

  return addHexPrefix(combinedHex);
}
github BANKEX / PlasmaETHexchange / lib / Block / blockHeader.js View on Github external
serializeSignature(signatureString) {
    const signature = stripHexPrefix(signatureString);
    let r = ethUtil.addHexPrefix(signature.substring(0,64));
    let s = ethUtil.addHexPrefix(signature.substring(64,128));
    let v = ethUtil.addHexPrefix(signature.substring(128,130));
    r = ethUtil.toBuffer(r);
    s = ethUtil.toBuffer(s);
    v = ethUtil.bufferToInt(ethUtil.toBuffer(v));
    if (v < 27) {
        v = v + 27;
    }
    v = ethUtil.toBuffer(v);
    this.r = r;
    this.v = v;
    this.s = s;
  }
github SuperblocksHQ / ethereum-studio / packages / editor / src / services / evm / src / evm.js View on Github external
function sendRawTransaction(data, callback) {
    var tx = new Transaction(data);
    _debugLog(
        '[Transaction] sending raw data from [' +
            utils.addHexPrefix(tx.from.toString('hex')) +
            '] to [' +
            utils.addHexPrefix(tx.to.toString('hex')) +
            ']'
    );

    _vm.blockchain.getHead(function(err, block) {
        var timeNowInSeconds = Math.floor(Date.now() / 1000);
        var nextBlock = new Block();
        nextBlock.header.number = blockNumber() + 1;
        nextBlock.header.difficulty = block.header.difficulty;
        nextBlock.header.parentHash = block.hash();
        nextBlock.header.timestamp = new Buffer(
            _pad(timeNowInSeconds.toString(16)),
            'hex'
        );
        nextBlock.transactions.push(tx);

        var transactionHash = utils.bufferToHex(tx.hash());
github Ethbet / ethbet / alpha / src / utils / balanceService.js View on Github external
async function withdraw(web3, amount) {
  const ethbetInstance = await contractService.getDeployedInstance(web3, "Ethbet");

  let results = await ethbetInstance.withdraw(amount, { from: web3.eth.defaultAccount, gas: 100000 });

  if (ethUtil.addHexPrefix(results.receipt.status.toString()) !== "0x1") {
    throw  new Error("Contract execution failed")
  }

  return results;
}