I'm trying to transfer some test ether from one Metamask address to another using the private key that I exported from it. But it always return a error code of -32000 with a message of 'Invalid sender'.

import web3 
import json
from eth_account import Account
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://ropsten.infura.io/v3/apiKey'))
acct = Account.privateKeyToAccount('Private key from Metamask')
nonce = w3.eth.getTransactionCount(acct.address)
transaction = {'
to' : toAccount,
'value': 1000000000,
'gas': 2000000,
'gasPrice': 234567897654321,
'nonce': nonce,
'chainId': 1
key = acct.privateKey
signed = w3.eth.account.signTransaction(transaction, key)

1 Answer 1


Usually, error -32000 means that the transaction signature is wrong.

The issue is chainId, because chainId is important during the transaction signing. Basically, your Python code signs the transaction with chainId: 1, but the infura ropsten node does not recognize the signature, because it expects chainId: 3.

1 is mainnet's chain id.

For ropsten you should use chain id 3. You can find list of network ids here.

P. S.

It's unrelated, but you only need 21000 gas to do a simple ether transfer and you probably should get your gasPrice from web3.


Your Answer

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

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