I'm encountering a problem that I'm not able to solve. The code should launch a configured transaction with the details object. The current configuration is set to Ropsten and I am using the INFURA API.

const EthereumTx = require('ethereumjs-tx');

const proveTransaction = async () => {

  let details = {
      "to": process.env.DESTINATION_WALLET_ADDRESS,
      "value": web3.utils.toHex( web3.utils.toWei(amountToSend.toString(), 'ether') ),
      "gas": 21000,
      "gasPrice": gasPrices.low * 1000000000, // converts the gwei price to wei
      "nonce": nonce,
      "chainId": 3 // EIP 155 chainId - mainnet: 1, ropsten: 3, rinkeby: 4 (https://ethereum.stackexchange.com/questions/17051/how-to-select-a-network-id-or-is-there-a-list-of-network-ids/17101#17101)
  const transaction = new EthereumTx(details)

This is the output on the console of NodeJS:

(node:80043) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The field to must have byte length of 20
    at Transaction.setter [as to] (/Users/sahelanthropus/progetti/nodejs/node_modules/ethereumjs-tx/node_modules/ethereumjs-util/dist/index.js:658:9)
    at /Users/sahelanthropus/progetti/nodejs/node_modules/ethereumjs-tx/node_modules/ethereumjs-util/dist/index.js:708:63
    at Array.forEach (<anonymous>)
    at Object.exports.defineProperties (/Users/sahelanthropus/progetti/nodejs/node_modules/ethereumjs-tx/node_modules/ethereumjs-util/dist/index.js:707:14)
    at new Transaction (/Users/sahelanthropus/progetti/nodejs/node_modules/ethereumjs-tx/es5/index.js:112:13)
    at proveTransaction (/Users/sahelanthropus/progetti/nodejs/routes/index.js:77:23)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

What do you suggest to check?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.