Kyle Pearson
Kyle Pearson

Reputation: 87

Invalid sender on signed transaction - mumbai polygon

I have the same smart contract deployed on mumbai as I do on ropsten to mint nfts, nothing too fancy. I then set up some python code with the web3 library to call the minting function. The code works properly when I test on ropsten but it fails when I try on mumbai. I have concerns about this failing on the polygon main net as well. I think I am using the proper chainId for each respective network. The error code I get when signing a transaction and sending the raw version is: {‘code’: -32000, ‘message’: ‘invalid sender’} . Do you know what could be going on?

import os
from web3 import Web3
from web3.middleware import geth_poa_middleware
from eth_account import Account

w3 = Web3(Web3.HTTPProvider(f"https://polygon-mumbai.infura.io/v3/{os.environ['WEB3_INFURA_PROJECT_ID']}"))
#w3 = Web3(Web3.HTTPProvider(f"https://polygon-mainnet.infura.io/v3/{os.environ['WEB3_INFURA_PROJECT_ID']}"))
#w3 = Web3(Web3.HTTPProvider(f"https://ropsten.infura.io/v3/{os.environ['WEB3_INFURA_PROJECT_ID']}"))

w3.middleware_onion.inject(geth_poa_middleware, layer=0)
print(w3.isConnected())

addr = "0x0D3C0D1C13a973DEFAe0dBA184081bDE0eD55B4C" # DMT on Polygon Mumbai
#addr = "0x74a4bf35Ec669A500541c1137A1fcDfa5f45194c" # DMT on Ropsten

acct = Account.privateKeyToAccount(os.environ['PRIVATE_KEY'])

#abi = ... # lots of stuff

contract_instance = w3.eth.contract(address=w3.toChecksumAddress(addr), abi=abi)
print(contract_instance.functions.lastTokenId().call())

nonce = w3.eth.get_transaction_count(acct.address)
test = 'https://ipfs.io/ipfs/mydata'
tx_hash = contract_instance.functions.autoMint(acct.address, test).buildTransaction({
    'from': acct.address,
    'chainId': 80001, # mumbai
    #'chainId': 3, # ropsten
    'gas': int(1e6),
    'maxFeePerGas': w3.toWei('2', 'gwei'),
    'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
    'nonce': nonce
})

signed_txn = w3.eth.account.sign_transaction(tx_hash, private_key=acct.privateKey)
tx_sent = w3.eth.send_raw_transaction(signed_txn.rawTransaction)

The provider I'm using is infura to access the blockchain over http. Do you think this error originates with their api?

Upvotes: 1

Views: 1772

Answers (1)

Kyle Pearson
Kyle Pearson

Reputation: 87

Fixed it using the fee structure from before 1559

tx_hash = contract_instance.functions.automint(acct.address, test).buildTransaction({
    'chainId': 0x13881, # mumbai
    #'chainId': 3, # ropsten
    'gasPrice': w3.toHex(w3.toWei('20', 'gwei')),
    'nonce': nonce,
    'from': acct.address
})

Upvotes: 0

Related Questions