I'm trying to test with the new 1559 style tx but have encountered the below issue where it is still wanting me to include a 'gasPrice' field.
simplified relevant code section:
acct = w3.eth.account.privateKeyToAccount(key)
signed_txn = acct.sign_transaction(dict(
nonce=nonce,
chainId=3,
# gasPrice=self.w3.eth.gas_price,
gas=21000,
maxFeePerGas=self.w3.toWei(1, 'gwei'),
maxPriorityFeePerGas=self.w3.toWei(0.5, 'gwei'),
to=address_to,
value=w3.toWei(eth_value, 'ether'),
data=b'',
),
)
tx_hash = HexBytes(w3.eth.send_raw_transaction(signed_txn.rawTransaction)).hex()
output:
File "test2.py", line 56, in <module>
test_acc.send_eth_ropsten(address_to=test_acc.address, eth_value=0.00001, nonce=test_acc.update_nonce())
| | -> <myacct.MyAcct object at 0x000002271E4D7580>
| -> <myacct.MyAcct object at 0x000002271E4D7580>
-> <myacct.MyAcct object at 0x000002271E4D7580>
File "C:\Users\pipe3\PycharmProjects\batchTransfer\myacct.py", line 279, in send_eth_ropsten
signed_txn = acct.signTransaction(dict(
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_account\signers\local.py", line 96, in signTransaction
return self.sign_transaction(transaction_dict)
| -> {'nonce': 29, 'chainId': 3, 'gas': 21000, 'maxFeePerGas': 1000000000, 'maxPriorityFeePerGas': 500000000, 'to': '...
-> <eth_account.signers.local.LocalAccount object at 0x000002271E8ADAC0>
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_account\signers\local.py", line 99, in sign_transaction
return self._publicapi.sign_transaction(transaction_dict, self.key)
| | -> <eth_account.signers.local.LocalAccount object at 0x000002271E8ADAC0>
| -> {'nonce': 29, 'chainId': 3, 'gas': 21000, 'maxFeePerGas': 1000000000, 'maxPriorityFeePerGas': 500000000, 'to': '...
-> <eth_account.signers.local.LocalAccount object at 0x000002271E8ADAC0>
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_utils\decorators.py", line 18, in _wrapper
return self.method(obj, *args, **kwargs)
| | | -> {}
| | -> ({'nonce': 29, 'chainId': 3, 'gas': 21000, 'maxFeePerGas': 1000000000, 'maxPriorityFeePerGas': 500000000, 'to': '...
| -> <eth_account.account.Account object at 0x000002271D024F70>
-> <eth_utils.decorators.combomethod object at 0x000002271CEAF3A0>
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_account\account.py", line 742, in sign_transaction
) = sign_transaction_dict(account._key_obj, sanitized_transaction)
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_account\_utils\signing.py", line 32, in sign_transaction_dict
unsigned_transaction = serializable_unsigned_transaction_from_dict(transaction_dict)
| -> {'nonce': 29, 'chainId': 3, 'gas': 21000, 'maxFeePerGas': 1000000000, 'maxPriorityFeePerGas': 500000000, 'to': '...
-> <function serializable_unsigned_transaction_from_dict at 0x000002271C8A9AF0>
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_account\_utils\legacy_transactions.py", line 40, in serializable_unsigned_transaction_from_dict
assert_valid_fields(transaction_dict)
| -> {'nonce': 29, 'chainId': 3, 'gas': 21000, 'maxFeePerGas': 1000000000, 'maxPriorityFeePerGas': 500000000, 'to': '...
-> <function assert_valid_fields at 0x000002271CD7A4C0>
File "C:\Users\pipe3\PycharmProjects\batchTransfer\venv\lib\site-packages\eth_account\_utils\legacy_transactions.py", line 93, in assert_valid_fields
raise TypeError("Transaction must include these fields: %r" % missing_keys)
-> {'gasPrice'}
TypeError: Transaction must include these fields: {'gasPrice'}
I have tried building the tx with/without either or both of the below two fields but I kept getting the same error:
maxFeePerGas=self.w3.toWei(1, 'gwei'),
maxPriorityFeePerGas=self.w3.toWei(0.5, 'gwei'),
I suspect I need to change something in this line but I'm not too sure how:
tx_hash = HexBytes(w3.eth.send_raw_transaction(signed_txn.rawTransaction)).hex()
I fixed this in #2099, can you give it a try? (gh pr checkout 2099)
I fixed this in #2099, can you give it a try? (
gh pr checkout 2099)
Thanks for replying. I'm not too familiar with the github cli and my production environment is offline. Is there anyway to include #2099 without Internet? I don't need this fixed urgently so I can wait till the next update comes out get install it via a .whl file.
I'll test #2099 in an online environment and get back to you anyway.
I fixed this in #2099, can you give it a try? (
gh pr checkout 2099)
I tried editing the web3/middleware/gas_price_strategy.py file with the changes from #2099 directly and tested. However I am still getting the same issue.
Actually looking into the stack trace now, am I right to assume that the 'eth_account' is the actual culprit here not web3?
Can you check if your tx includes {'type': 2} field? Web3.py should inject it automatically, but eth-account requires you to specify it explicitly.
Can you check if your tx includes
{'type': 2}field? Web3.py should inject it automatically, but eth-account requires you to specify it explicitly.
That's it! Thank you so much! I wonder where/how did you know that? I couldn't find much info on eth-account regarding 1559 apart from the release notes.
Edit: I found an example with the 'type' field in web3 documentation. Cheers
Most helpful comment
That's it! Thank you so much! I wonder where/how did you know that? I couldn't find much info on eth-account regarding 1559 apart from the release notes.
Edit: I found an example with the 'type' field in web3 documentation. Cheers