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
779 stars 235 forks source link

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

Closed jdiegosierra closed 5 years ago

jdiegosierra commented 5 years ago

I get this error making a typic signed call method transaction when I use ethereumjs-tx version 2.0.0, however It works well with 1.3.7.

PD. When I was working in geth node I also tryed settng the values of ChainID and NetworkID to the same value.

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

Library versions: node v10.15.3 "web3": "^1.0.0-beta.55" "ethereumjs-tx": "^2.0.0"

My code:


// Neither of them works
//let web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/c84e1407efba4b8e937804dbe25f92ba"));
let web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8504")); // Geth node

    web3.eth.getGasPrice().then((gasPrice) => {
        web3.eth.getTransactionCount(wallet, 'pending').then((nonce) => {
            let txParams = {
                nonce: web3.utils.toHex(nonce),
                gasLimit: web3.utils.toHex(gasLimit),
                gasPrice: web3.utils.toHex(gasPrice),
                from: wallet,
                to: contract,
                data: data,
                // chainId: web3.utils.toHex(3),
            }
            let tx = new Tx(txParams);
            let privKey = Buffer.from(key, 'hex');
            tx.sign(privKey);
            tx = "0x" + tx.serialize().toString('hex')
            web3.eth.sendSignedTransaction(tx)
                .on('transactionHash', (hash) => {
                    console.log(hash);
                })
                .on('receipt', (receipt) => {
                    console.log(receipt);
                })
                .on('confirmation', (confirmationNumber, receipt) => {
                    console.log( confirmationNumber);
                    console.log(receipt);
                })
                .on('error', console.error);
        })
    });
holgerd77 commented 5 years ago

@jdiegosierra Thanks for reporting this!

We have an apparent issue on too restrictive chain settings for v2.0.0 - originally caused within the chain/HF selecting Common library - see linked issue above - this here might be related.

What is PD as abbreviation? Do you think the network and chain ID setting you did is related here or did you mentioned this as a separate thing? To what values did you try to set this? What happened?

Thanks!

jdiegosierra commented 5 years ago

Ups. Sorry.. PD means "Post Scriptum" in Spanish. Just a mistake!

I tryed settng the values of ChainID and NetworkID to the same value because I read this https://github.com/ethereum/web3.js/issues/1040. But I don't know if It's is related... I tryed all what they said in the issue but I always got the same error.

sharf521 commented 5 years ago

const tx = new EthereumTx(txParams,{'chain':'ropsten'})

alcuadrado commented 5 years ago

Hola @jdiegosierra!

I just submitted a PR that has an example of how to create ropsten transactions. It's basically what @sharf521 :)

jdiegosierra commented 5 years ago

Thx @sharf521 & @alcuadrado !!

Skyge commented 5 years ago

Why should we specific the parameter: chain at the version 2.0.0, if I use 1.3.7, I do not have got to write the parameter: chain.

alcuadrado commented 5 years ago

Version 1.x had some really complicated logic to manage this, which lead to multiple bugs. v2 makes things more explicit, but also more robust.