Getting error while creating ethereum raw transaction

var rawTx = {
  nonce: '0x2a',
  gasPrice: '0x4a717c800',
  gasLimit: '0xc340',
  to: '0x73F7Ced8cc9D27DC426210c32fc6d0a40f941eE1',
  value: '0x2386f26fc10000',
  data: '',
  chainID: 4 
var cTx = await new EthereumTx(rawTx, { 'chain': 'rinkeby' });

try change data :'' to data:"0x"

| improve this answer | |
  • why does this work? – lhay86 Aug 18 at 9:54

Replace privateKey with Buffer.from(privateKey.slice(2), "hex").

| improve this answer | |
  • i am already using privatekey in buffer – Ishwar Chandra Tiwari Mar 4 at 6:13
  • @IshwarChandra: Did this method not work for you? If yes, then please elaborate on what error it gives you. – goodvibration Mar 4 at 7:51
  • i have used your given solution but i am still getting same error – Ishwar Chandra Tiwari Mar 4 at 8:16

This might be happening, because you are trying to sign the raw transaction with private key in string format, but it has to be hex. Change:



cTx.sign(new Buffer(privateKey, 'hex'))

And on a side note, here var cTx = await new EthereumTx(rawTx, { 'chain': 'rinkeby' }); you don't have to pass chain parameter, you already specified to which blockchain network the transaction should be sent in rawTx where you placed this parameter chainID: 4. Full list with blockchain networks can be found here.

| improve this answer | |

ethereum-utils checks string fields if they are hex. When you send data field as empty, then it throws the error. You can send data as '0x' like they said above.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.