首页 > 解决方案 > 使用 ethereumjs-tx 发送签名交易时如何修复无效发件人错误?

问题描述

尝试发送签名交易时收到无效发件人。这是错误:

Uncaught (in promise) Error: Returned error: invalid sender

这是代码:

  var privateKey = Buffer.from('private key without 0x', 'hex');

  var rawTx = {
    nonce: await web3.utils.toHex(web3.eth.getTransactionCount(account1)),
    to: account2,
    value: web3.utils.toHex(web3.utils.toWei('1', 'ether')),
    gasLimit: web3.utils.toHex(21000),
    gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
  }

  var tx = new Transaction(rawTx, {'chain':'ropsten'});
  tx.sign(privateKey);

  var serializedTx = tx.serialize();
  console.log('serializedTx', serializedTx)

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

可能是什么问题呢?

标签: blockchainethereumweb3js

解决方案


推荐阅读