Hi,
I want to create a simple Ethereum Görli testnet transaction, very similar to this tutorial: Use Python - Infura Docs
For this, I copied the code from there, it looks like this (besides my API number):
import os
from dotenv import load_dotenv
from web3 import Web3
load_dotenv()
infura_url = "https://goerli.infura.io/v3/<my API number>"
private_key = os.getenv('PRIVATE_KEY')
from_account = '0xa43190EF71561A9229D8ddC5449d68FFE518b1D8'
to_account = '0x37d1215743ACf59B85f2DDE7Ab103f2BBC5a568F'
web3 = Web3(Web3.HTTPProvider(infura_url))
nonce = web3.eth.getTransactionCount(from_account)
tx = {
'type': '0x2',
'nonce': nonce,
'from': from_account,
'to': to_account,
'value': web3.toWei(0.01, 'ether'),
'maxFeePerGas': web3.toWei('250', 'gwei'),
'maxPriorityFeePerGas': web3.toWei('3', 'gwei'),
'chainId': 5
}
gas = web3.eth.estimateGas(tx)
tx['gas'] = gas
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print("Transaction hash: " + str(web3.toHex(tx_hash)))
When I run the code, it creates an error in the line gas = web3.eth.estimateGas(tx):
Exception has occurred: ValueError
{'code': -32602, 'message': 'invalid argument 0: json: cannot unmarshal non-string into Go struct field TransactionArgs.maxFeePerGas of type *hexutil.Big'}
File "C:\Users\userA\Documents\GitHub\solidity_playground_1\eip1559_tx.py", line 27, in <module>
gas = web3.eth.estimateGas(tx)
Can you please help me to resolve it? Thanks in advance!