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)
w3.eth.sendRawTransaction(signed.rawTransaction)