sample code:
var ethNodeUrl = 'http://localhost:8545';
var provider = new Web3.providers.HttpProvider(ethNodeUrl);
var web3 = new Web3(provider);
var accountString = '{............encrypted account.........}';
var account = web3.eth.accounts.decrypt(JSON.parse(accountString), 'password');
account.signTransaction({
from: account.address,
to: '<some target>',
value: 8704500000000000,
gas: 200000
}).then((tx) => {
web3.eth.sendSignedTransaction(tx.rawTransaction).then((response) => {
console.log(response);
});
});
throws "Unhandled rejection Error: Returned error: invalid sender".
genesis.json has non-zero chainId. FROM account has sufficient balance. Works fine if i "unlock the account" in geth and then use sendTransaction(). dont want to do that as that has security issues (even if unlock timeout is very small).
@skkiran - this could be related to #932?
@lukehedger does not seem to be related. signTransaction is working fine, and im even able to retrieve the signer address using web3.eth.accounts.recoverTransaction(tx.rawTransaction).
decoded tx.rawTransaction using ethereumjs-tx, and it seems to match the transaction RLP spec.
Switched to "testrpc" and got same error as #932. Worked around it by using "ethereumjs-tx" for signing transaction and then sending it using sendSignedTransaction. sample code that works with testrpc:
var ethNodeUrl = 'http://localhost:8545';
var provider = new Web3.providers.HttpProvider(ethNodeUrl);
var web3 = new Web3(provider);
var accountString = '{............encrypted account.........}';
var account = web3.eth.accounts.decrypt(JSON.parse(accountString), 'password');
web3.eth.getTransactionCount(account.address).then((nonce) => {
var tx = new Tx({
nonce: nonce,
from: account.address,
to: '<some target>',
value: 8704500000000000,
gasLimit: 200000
});
tx.sign(new Buffer(account.privateKey.substr(2), 'hex'));
web3.eth.sendSignedTransaction('0x'+tx.serialize().toString('hex')).then((response) => {
console.log(response);
});
});
not sure why it is not working only with geth. you can close this if you feel it is not a problem with web3.
I get the same error in the browser while the tests with node work fine.
In order to debug, I tried using eth.accounts.recoverTransaction(rawTransaction) again, this works fine on node but fails in the browser with: TypeError: Cannot read property 'redMul' of null
the problem is with EIP155 and matching ChainID and NetworkID.
If you set the two values above to the same value it will work. In case of geth --dev ... the networkID should be 1337.
Tried with geth again and it works fine with ChainID and NetworkID set to 10. With ChainID 1337, i get #932. I will close this for now.
solved by change the ChainID.
0: Olympic, Ethereum public pre-release testnet
1: Frontier, Homestead, Metropolis, the Ethereum public main network
1: Classic, the (un)forked public Ethereum Classic main network, chain ID 61
1: Expanse, an alternative Ethereum implementation, chain ID 2
2: Morden, the public Ethereum testnet, now Ethereum Classic testnet
3: Ropsten, the public cross-client Ethereum testnet
4: Rinkeby, the public Geth PoA testnet
8: Ubiq, the public Gubiq main network with flux difficulty chain ID 8
42: Kovan, the public Parity PoA testnet
77: Sokol, the public POA Network testnet
99: Core, the public POA Network main network
7762959: Musicoin, the music blockchain
Ref -> https://ethereum.stackexchange.com/questions/17051/how-to-select-a-network-id-or-is-there-a-list-of-network-ids/17101#17101
I ran into this issue.
Make sure if you supply networkid when starting geth that it is the same in all places (ABIs, Provider, Genesis, Geth)
Eg. I was using 6660001 everywhere
My genesis had 666001 (missing 1 '0')
And i got the invalid sender error.
Change
let tx = new Tx(rawTx);
to
let tx = new Tx(rawTx, { chain: 'ropsten', hardfork: 'petersburg' });
still facing this issues {"jsonrpc":"2.0","id":0,"error":{"code":-32000,"message":"invalid sender"}
Most helpful comment
the problem is with EIP155 and matching ChainID and NetworkID.
If you set the two values above to the same value it will work. In case of
geth --dev ...the networkID should be 1337.