19

Good afternoon, after having been developing a blockchain web app for some months, it's the first time I get this error when making a transaction.

ValueError: {'code': -32000, 'message': 'only replay-protected (EIP-155) transactions allowed over RPC'}

This is my code. It has always worked, and I guess it's not a matter of code, it might be just a matter of Web3, but I'm asking just in case. Thanks in advance.

tx = {
    'nonce': nonce,
    'to': account_2,
    'value': web3.toWei(float_amount, 'ether'),
    'gas': 21000,
    'gasPrice': web3.toWei(50, 'gwei')
}
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
tx_hash = web3.eth.send_raw_transaction(web3.toHex(signed_tx.rawTransaction))
1
  • 1
    I don't know much about py but can you add the chain Id somewhere in the config of your project like we do in truffle :/ or try to call the chain Id and see if you get a value
    – Majd TL
    Mar 9, 2021 at 16:13

2 Answers 2

25

You'll need to add chainId to your transaction object to save your tx from being replayed on other chains.

tx = {
    'chainId': 3, // for ropsten
    'nonce': nonce,
    'to': account_2,
    'value': web3.toWei(float_amount, 'ether'),
    'gas': 21000,
    'gasPrice': web3.toWei(50, 'gwei')
}

Check here for chain IDs of all EVM based chain

1
  • 2
    You just saved my life. Thank you so much man
    – Busto
    Mar 9, 2021 at 16:58
5

Another bypass is to run the node using --rpc.allow-unprotected-txs. It is helpful especially in cases where you can't specify the ID.

2
  • This worked for me. But is this option unsecure? Nov 11, 2022 at 17:14
  • RPC is necessary but I'm asking about that is sending non EIP155 transactions from RPC unsecure? Nov 12, 2022 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.