ethereumjs-tx Returned error: invalid sender
ethereumjs-tx Returned error: invalid sender
Loading saved threads...
Cryptoineer · External communityPost link
External question — Ethereum Stack Exchange
Author: Cryptoineer
Original post: https://ethereum.stackexchange.com/questions/87606
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
When i am trying to send signed transaction via ethereumjs-tx. I get this
Returned error: invalid sender
web3Http.eth.getTransactionCount(myAddress,"pending").then(function(blockcount){
result = web3Http.utils.toWei(amt.toString(), 'ether');
count = blockcount;
var rawTransaction = {
"from":myAddress,
"gasPrice":web3Http.utils.toHex(20* 1e9),
"gasLimit":web3Http.utils.toHex(210000),
"to":contractAddress,"value":"0x0",
"data":contract.methods.approve(fromAddress,web3Http.utils.toHex(result)).encodeABI(),
"nonce":web3Http.utils.toHex(count)
}
var transaction = new Tx(rawTransaction,{'chain':'rinkeby',hardfork: 'petersburg'});
transaction.sign(Buffer.from(process.env.Key, 'hex'));
web3Http.eth.sendSignedTransaction('0x'+transaction.serialize().toString('hex'))
.on('receipt', ((data)=>{
resolve(data);
}))
Quote
Report
nameless · External communityPost link
External answer — Ethereum Stack Exchange
Author: nameless
Original post: https://ethereum.stackexchange.com/a/131511
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Change the below
const Tx = require('ethereumjs-tx').Transaction;
var transaction_data = {
"from": myAddress,
"gasPrice": web3Http.utils.toHex(20 * 1e9),
"gasLimit": web3Http.utils.toHex(210000),
"to": contractAddress,
"value": "0x0",
"data": contract.methods.safeTransferFrom(myAddress, toAddress, tokenId).encodeABI(),
}
var privateKey = Buffer.from('abcde', 'hex')
var transaction = new Tx(transaction_data,{ chain: 'ropsten' , hardfork: 'petersburg' });
transaction.sign(privateKey);
web3Http.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex'))
.on('transactionHash', console.log);
to the below
const Tx = require('ethereumjs-tx').Transaction;
var transaction_data = {
"from": myAddress,
"gasPrice": web3Http.utils.toHex(20 * 1e9),
"gasLimit": web3Http.utils.toHex(210000),
"to": contractAddress,
"value": "0x0",
"data": contract.methods.safeTransferFrom(myAddress, toAddress, tokenId).encodeABI(),
}
var privateKey ='abcde'
web3Http.eth.accounts.signTransaction(transaction_data, privateKey)
.then(function(value){
web3Http.eth.sendSignedTransaction(value.transaction_data)
.then(function(response){
console.log("response:" + JSON.stringify(response, null, ' '));
})
})
web3Http.eth.accounts.signTransaction
will take the burden of including the correct chainId and nonce .
Reference:
https://github.com/ChainSafe/web3.js/issues/1040
Quote
Report
Post Reply
Checking account access…