Invalid Sender (code: -32000

Hi! i need help with this issue: (code: -32000 error: invalid sender).
When i try to do a transaction with ropsten nodes all works fine, but, if i try to do a transaction with Polygon nodes, i get the last error (ValueError: {‘code’: -32000, ‘message’: ‘invalid sender’}).

(on “chainId:” appears that i use “89” (like Moralis nodes say), but i tried to use chainId 89, 0x89, 137 and 0x137).

It’s my code:
w3 = Web3(Web3.WebsocketProvider(‘wss://speedy-nodes-nyc.moralis.io/[redacted]/polygon/mainnet/ws’))

quickswap_router = ‘0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff’
matic_token = Web3.toChecksumAddress(‘0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270’)
usdc_token = Web3.toChecksumAddress(‘0x2791bca1f2de4661ed88a30c99a7a9449aa84174’)

router = Web3.toChecksumAddress(quickswap_router)
abi = llamadas_poly.get_abi(quickswap_router)
path = [matic_token, usdc_token]
contract = w3.eth.contract(address=router, abi=abi)

tx = contract.functions.swapExactETHForTokens(
int(130000*0.99),
path,
address1,
int(time.time())
).buildTransaction({
‘chainId’: 89,
‘gas’: int(llamadas_poly.gasprice()*1.5),
‘value’: 100000000000000000,
‘maxFeePerGas’: llamadas_poly.maxgasprice()*2,
‘maxPriorityFeePerGas’: llamadas_poly.maxgasprice(),
‘nonce’: llamadas_poly.get_nonce(BOT_PRUEBAS_ACCOUNT)
})

signed_tx = w3.eth.account.sign_transaction(tx, acc1_privatekey)
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)

I use the same acc1_privatekey to do transactions with ropsten node and works fine, so, i thinks it was not the problem.
(I’m using Python).

Thakns in advance!

1 Like

you could try something like this before signing (taken from the internet):

tx.v = chainId
tx.nonce  = web3.utils.toHex(web3.eth.getTransactionCount(account))

python syntax may be different

I try it and i got the same issue.
Nonce count take it correctly and chainId must be correct.

If you change the speedy node address to one that is not from Moralis then it works?

You can also try to update the web3 library in case that it doesn’t process correctly the chain that has to be included in the signature parameters.

If i use Speedy nodes with Ropsten chain, i can do transactions, yes.
I’ll update it!

Using Infura Polygon node i can’t do a transaction.

The chains for which it works have an id lower than 128?

Yeah, Ropsten is 3.
I tried using 137 and 0x137 (Pilygon Id), and using 89 and 0x89 (for Moralis, Polygon is Id 89 if i’m not wrong).

Others requests i can do it (like, get_block, get_transactionCount, etc…)

Yes, other requests don’t require that signature , that chain id is included in the signature

The chain id for polygon should be 137 I think. Where did you find that 89?
You can try with chain id 137 & 0x80

I found it on “https://admin.moralis.io/web3Api”, into “chainList” you can see this list:
eth, 0x1, ropsten, 0x3, rinkeby, 0x4, goerli, 0x5, kovan, 0x2a, polygon, 0x89, mumbai, 0x13881, bsc, 0x38, bsc testnet, 0x61, avalanche, 0xa86a, fantom, 0xfa

I try with 137 and 0x80 with same error “invalid sender”.
Maybe i have wrong my code?

0x89 = 137

you should use 0x89 or 137, they have the same value

can you try with Mumbai for a simpler transaction, for example only to send matic from one address to another address?

it may work if you use javascript, you could also try to decode your raw transaction to see how it looks like, for example using a transaction decoder like: https://www.ethereumdecoder.com/

Yes, i just do it trying to send a transfer between two accounts in Ropsten and Polygon and all works correctly.

transfer works correctly in Polygon from your python code, but that transaction in particular with contract.functions.swapExactETHForTokens doesn’t work on Polygon?

I tried to do another tx with other Router and it’s the same.
I’m going to post the full error i got on console:
Traceback (most recent call last):
File “C:\Users\USER\IdeaProjects\Geth - PROJECT.py”, line 67, in

tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)

File “C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\eth.py”, line 698, in send_raw_transaction

return self._send_raw_transaction(transaction)

File “C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\module.py”, line 57, in caller

result = w3.manager.request_blocking(method_str,

File “C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\manager.py”, line 187, in request_blocking

return self.formatted_response(response,

File “C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\web3\manager.py”, line 168, in formatted_response
raise ValueError(response[“error”])

ValueError: {‘code’: -32000, ‘message’: ‘invalid sender’}