0

I previously used Ganche to deploy a solidity contract in python with web3py and it worked with given http provider & account details. But now I want to deploy the flask application that connects to this, so I created an account on Infura on the Sepolia testnet and put given link w my api key as the new provider, created a metamask account and added test Ether for Sepolia, but when I run the app now with these new values, I get the following error:

MethodUnavailable(error) web3.exceptions.MethodUnavailable: {'code': -32601, 'message': 'The method eth_sendTransaction does not exist/is not available'}

These are the lines that use the values, if it helps. The error points to the last line:

w3 = Web3(Web3.HTTPProvider(os.getenv('HTTPProvider')))
chain_id = int(os.getenv('chain_id'))
my_address = os.getenv('address')
private_key = os.getenv('private_key')  # should start with 0x

TraceLink = w3.eth.contract(abi=ABI, bytecode=bytecode)

# Deploy the contract
tx_hash = TraceLink.constructor().transact({
    "from": my_address,
    "gas": 6_000_000,  # Adjust the gas limit as needed
})

I'm not sure what I'm doing wrong, any suggestions?

2 Answers 2

1

Infura doesn't support eth_sendTransaction. (For it to support that, it would need to know your private key, but it's a shared public node.)

You need to either sign the transaction yourself and then send via eth_sendRawTransaction or use a provider that can hold private keys like MetaMask in the browser.

0

@ruby_newbie is correct. You can sign and send the transaction but you may also have to adjust maxFeePerGas and maxPriorityFeePerGas in order to have your transaction processed quicker.

w3 = Web3(Web3.HTTPProvider(os.getenv('HTTPProvider')))
my_address = os.getenv('address')
private_key = os.getenv('private_key')  # should start with 0x

TraceLink = w3.eth.contract(abi=ABI, bytecode=bytecode)

# Deploy the contract
txn = TraceLink.constructor().buildTransaction({
    "from": my_address,
    "gas": 6_000_000,  # Adjust the gas limit as needed
})
signed_txn = w3.eth.account.sign_transaction(txn, private_key=private_key)
txn_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)

# Wait for the transaction to be mined, and get the transaction receipt
txn_receipt = w3.eth.wait_for_transaction_receipt(txn_hash)

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.