Solvedweb3.js sendSignedTransaction() error: invalid sender

Description

Expected behavior

Calling `web3.eth.sendSignedTransaction(data)` should succeed.

Actual behavior

Calling `web3.eth.sendSignedTransaction(data)` 
returns `error: {"code":-32000,"message":"invalid sender"}`.

Steps to reproduce the behavior

const Tx = require('ethereumjs-tx');
const privateKey = new Buffer('e33xxxxc0fd109', 'hex')

const rawTx = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000',
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000',
  value: '0x00',
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}

const tx = new Tx(rawTx);
tx.sign(privateKey);

const serializedTx = tx.serialize();

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);

Error Logs

error: {"code":-32000,"message":"invalid sender"}

Versions

  • web3.js: 1.0.0-beta.55
  • nodejs: v11.10.1
  • browser: Chrome
16 Answers

✔️Accepted Answer

@paulrberg If you want to use the version: 2.0.0, you should add extra parameter chain like this

var tx = new Tx(rawTx, {'chain':'ropsten'});

Other Answers:

But this is not a bug of web3.js, it is due to the package ethereumjs-tx at the version 2.0.0, if you use the version 1.3.7, it will not have this error.

I can also confirm that ethereumjs-tx version 2.0.0 is broken:

error: {"code":-32000,"message":"invalid sender"}

Reverting to 1.3.7 fixes the problem.

@paulrberg If you want to use the version: 2.0.0, you should add extra parameter chain like this

var tx = new Tx(rawTx, {'chain':'ropsten'});

This works 100%

Thanks.

var tx = new Tx(rawTx, {'chain':'ropsten'});
will it work for binance smart chain ?

const Tx = require('ethereumjs-tx').Transaction;
var Web3 = require('web3')
var web3 = new Web3(new Web3.providers.HttpProvider('https://bsc-dataseed1.binance.org:443'))

More Issues: