0

Im trying to use the following code with nodejs to create a raw transaction:

const ethTx = require('ethereumjs-tx').Transaction;

const txParams = {
  nonce: '0x0',
  gasPrice: '0x3B9ACA00', 
  gasLimit: '0x30000',
  to: '0x8b74c9f20Da3Eb2F77a93f23563F605742C37b34', 
  value: '0x00',
  chainId: '0x3'
};


const tx = new ethTx(txParams);
const privKey = Buffer.from('26c3bc1ed44e198f044309325f424734a9557c531473738c3e12ee15f08953d8', 'hex');



tx.sign(privKey);
const serializedTx = tx.serialize();
const rawTx = '0x' + serializedTx.toString('hex');
console.log(rawTx)

Inputting the result in geth console gives me the following error:

eth.sendRawTransaction('0xf86480843b9aca0083030000948b74c9f20da3eb2f77a93f23563f605742c37b34808025a0fc64270ed2768996859287f780e3477c2c081b3b7409e38b3210f0ebab7a156fa049e2d9eff1215a8f056f02f5e7ed06f8e856ffc2745fe2443a33b97629a868f0')
Error: invalid sender
    at web3.js:6365:9(45)
    at send (web3.js:5099:62(34))
    at <eval>:1:23(4)

1 Answer 1

0

This was solved by removing chainId in txParams and changing the const tx = new ethTx(txParams); line to const tx = new ethTx(txParams, { chain: 'goerli' });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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