Hello
I am trying to sign a transaction on the polygon network with Web3.py, but when I submit the transaction, I get the following error.
ValueError: {'code': -32000, 'message': 'invalid sender'}
The funny thing is that it works when I run the whole thing through the ETH mainnet Endpoint. Does anyone know where the error could be?
Not working code (Polygon):
from web3 import Web3
import json
w3 = Web3(Web3.HTTPProvider('https://speedy-nodes-nyc.moralis.io/XXX/polygon/mainnet'))
# dummy account
private_key = "09f8998d3d0a5776cb9d656205f0e1734493de179fbe7fedd9d7107472ecbbf8"
address_user = "0x08d7FA722746e2f57aF9723A5f276e1DdF1cef73"
nonce = w3.eth.get_transaction_count(address_user)
# contract
abi = json.loads("...ABI...")
address = "...contract address..."
contract = w3.eth.contract(abi=abi, address=address)
# txn
deposit_txn = contract.functions.deposit(13, 0).buildTransaction({
"gas": 70000,
'maxFeePerGas': w3.toWei('2', 'gwei'),
'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
'nonce': nonce,
'from': address_user,
'chainId': 0x89
})
signed_txn = w3.eth.account.sign_transaction(deposit_txn, private_key=private_key)
w3.eth.sendRawTransaction(signed_txn.rawTransaction)
The same code gives me the error code âinsufficient funds for gas * price + valueâ when I use the ETH endpoint and remove âchainIdâ: 0x89 from the transaction. From this I conclude that it works for ETH and only polygon causes a problem.
Hopefully someone here can help me, because I have no idea what else to try
Many thanks in advance