Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug with method buildTransaction in the version 5.25.0 #2307

Closed
AHTOH2001 opened this issue Jan 18, 2022 · 6 comments
Closed

bug with method buildTransaction in the version 5.25.0 #2307

AHTOH2001 opened this issue Jan 18, 2022 · 6 comments

Comments

@AHTOH2001
Copy link

  • Version: 5.25.0
  • Python: 3.9.7
  • OS: linux/win

What is wrong?

The buildTransaction method without specifying gasPrice raises ValueError {'code': -32601, 'message': 'the method eth_maxPriorityFeePerGas does not exist/is not available'}

Snippet to reproduce the issue

from web3 import Web3
import json

web3 = Web3(Web3.HTTPProvider("..."))
# Any ERC-20 contract
contract_addr = '...'
from_addr = '...'
to_addr = '...'

with open('abi.json', 'r') as fp:
    abi = json.load(fp)

contract = web3.eth.contract(contract_addr, abi=abi)

nonce = web3.eth.get_transaction_count(from_addr)
transaction = contract.functions.transfer(
    to_addr,
    web3.toWei(0.1, 'ether')
)
transaction = transaction.buildTransaction({
    'from': from_addr,
    'chainId': 56,
    'nonce': nonce,    
    # 'gasPrice': web3.toWei(5, 'gwei')
})

How can it be fixed?

  • Use previous version 5.24.0 in which it was working perfectly
  • Specify explicitly the gas price
@fselmo
Copy link
Collaborator

fselmo commented Jan 18, 2022

@AHTOH2001, thanks for reaching out. Ethereum transactions now default to the most efficient transaction type if the user does not provide fee values (gasPrice or max*FeePerGas fee values). This means it defaults to using maxFeePerGas and maxPriorityFeePerGas, opting for a dynamic fee transaction (type=2) over a legacy transaction.

What's going on here that is not ideal is that, currently, there is a geth-centric default in using eth_maxPriorityFeePerGas. Since this method is not on the Ethereum JSON-RPC specs, it shouldn't be expected to be implemented on all clients. We will be changing this in order to make the default value more flexible across different providers and that is being tracked here.

I'm assuming if you need to use gasPrice that your are either using a layer 2 provider or a provider for another chain that is not Ethereum. If so, this method is bound to the eth module, via the eth.contract utilities, so this would not be a bug. We recently added support for attaching external modules and this feature could be used to attach layer 2 (ideally coming soon) or alternate chain modules when those become available as well.

What happens when you provide a gasPrice is you override the dynamic fee transaction default that was in place, opting for a legacy transaction (which is less efficient in Ethereum), and it should work just as it did before.

I'm going to close this but if you feel like there is a bug here that hasn't been addressed, please feel free to reopen this issue.

@fselmo fselmo closed this as completed Jan 18, 2022
@AHTOH2001
Copy link
Author

Yea, you are right, I'm using bsc network with quick node provider, the reason why I think this is a bug is that using the same provider at the library version 5.25.0 it raises exception, although at the version 5.24.0 it works fine.

@AHTOH2001
Copy link
Author

And unfortunately I cannot re-open my own issue if a repo collaborator closed it.

@fselmo
Copy link
Collaborator

fselmo commented Jan 19, 2022

Please re-read my comment above. If using gasPrice explicitly works, this is how you will have to use the eth module on bsc. If it was the bsc module, this would be a bug. Best of luck.

@mikke555
Copy link

mikke555 commented Feb 3, 2024

I'm getting this warning when sending EIP-1559 style transaction over zkSync network:

.venv\lib\site-packages\web3\eth\eth.py:186: UserWarning: There was an issue with the method eth_maxPriorityFeePerGas. Calculating using eth_feeHistory

What would be the correct way if not using gasPrice?

@fselmo
Copy link
Collaborator

fselmo commented Feb 3, 2024

I'm getting this warning when sending EIP-1559 style transaction over zkSync network:

.venv\lib\site-packages\web3\eth\eth.py:186: UserWarning: There was an issue with the method eth_maxPriorityFeePerGas. Calculating using eth_feeHistory

What would be the correct way if not using gasPrice?

This warning happens when either maxPriorityFeePerGas or maxFeePerGas (or both) are not present in your transaction dictionary when sending a transaction. The in-house default way of calculating EIP-1559 fees is to call eth_maxPriorityFeePerGas to determine the value from the client that's running on whatever node you're connecting to. If that method is not available on the client then the fee is calculated using eth_feeHistory.

If you don't want to see this warning, you have to set your own values for maxFeePerGas and maxPriorityFeePerGas. Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants