ethereumjs / ethereumjs-tx

Project is in active development and has been moved to the EthereumJS VM monorepo.
https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/tx
Mozilla Public License 2.0
781 stars 236 forks source link

Error: Node error: {"code":-32000,"message":"invalid sender"} #167

Closed nbleoncc closed 5 years ago

nbleoncc commented 5 years ago

can someone help me out this error?

const Web3 = require('web3'); const EthereumTx = require('ethereumjs-tx').Transaction

if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { // set the provider you want from Web3.providers web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/c7c960727b5b41f380e1a1131dfe5ea9")); }

const privateKey = Buffer.from( 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex', )

const txParams = { nonce: '0x00', gasPrice: '0x09184e72a000', gasLimit: '0x2710', to: '0x0000000000000000000000000000000000000000', value: '0x00', data: '', chainId: 3 }

const tx = new EthereumTx(txParams) tx.sign(privateKey) const serializedTx = tx.serialize()

const feeCost = tx.getUpfrontCost() console.log('Total Amount of wei needed:' + feeCost.toString())

// Lets serialize the transaction

console.log('---Serialized TX----') console.log(tx.serialize().toString('hex')) console.log('--------------------')

console.log('Senders Address: ' + tx.getSenderAddress().toString('hex'))

// Cool now we know who sent the tx! Lets verify the signature to make sure it was not // some poser.

if (tx.verifySignature()) { console.log('Signature Checks out!') }

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

holgerd77 commented 5 years ago

There was a pretty similar issue opened and answered some days ago, please have a look: https://github.com/ethereumjs/ethereumjs-tx/issues/165

Will close, feel free to reopen if this doesn't solve it.

Skyge commented 5 years ago

@holgerd77 Please correct the solution location, it is #165.

holgerd77 commented 5 years ago

@Skyge Sorry, thanks, updated.