Skip to content

The method eth_maxPriorityFeePerGas does not exist/is not available #217

Closed

Description

@PLKuba

Hi,
I'm trying to perform a swap on spookyswap (fantom chain) using Uniswap-python.
However, I'm getting the following ValueError:

ValueError: {'code': -32601, 'message': 'the method eth_maxPriorityFeePerGas does not exist/is not available'}

I tried using multiple RPCs but all of them gave the same output.

NOTE:
I modified _netid_to_name in constats.py so that chainId 250 (fantom) is acceptable.

Code:

from uniswap import Uniswap

fantom_provider = 'https://rpc.ftm.tools/'

spookyswap_router_contract_addr = "0xf491e7b69e4244ad4002bc14e878a34207e38c29"

spookyswap_factory_contract_addr = "0x152eE697f2E276fA89E96742e9bB9aB1F2E61bE3"

weth_ftm = "0x74b23882a30290451A17c44f4F05243b6b58C76d"

dai_ftm = "0x8d11ec38a3eb5e956b052f67da8bdc9bef8abf3e"

amount = 0.00000001


spookyswap = Uniswap(address=spookyswap_address, private_key=spookyswap_private_key, version=version,
                    router_contract_addr=spookyswap_router_contract_addr,
                    factory_contract_addr=spookyswap_factory_contract_addr,
                    provider=fantom_provider)

spookyswap.make_trade(weth_ftm, dai_ftm, int(amount * 10**18), slippage = 0.2)

Full Error message:

Approving 0x74b23882a30290451A17c44f4F05243b6b58C76d...
Traceback (most recent call last):
  File "/Users/kuba/PycharmProjects/project/playground.py", line 111, in <module>
    print(spookyswap.make_trade(weth_ftm, dai_ftm, int(amount * 10**18), slippage = 0.2))
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/uniswap/decorators.py", line 29, in approved
    self.approve(token)
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/uniswap/uniswap.py", line 1053, in approve
    tx = self._build_and_send_tx(function)
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/uniswap/uniswap.py", line 1087, in _build_and_send_tx
    transaction = function.buildTransaction(tx_params)
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/contract.py", line 1079, in buildTransaction
    return build_transaction_for_function(
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/contract.py", line 1648, in build_transaction_for_function
    prepared_transaction = fill_transaction_defaults(web3, prepared_transaction)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/_utils/transactions.py", line 121, in fill_transaction_defaults
    default_val = default_getter(web3, transaction)
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/_utils/transactions.py", line 71, in <lambda>
    web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/eth.py", line 549, in max_priority_fee
    return self._max_priority_fee()
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/Users/kuba/PycharmProjects/project/venv/lib/python3.9/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32601, 'message': 'the method eth_maxPriorityFeePerGas does not exist/is not available'}

Activity

  1. liquid-8 commented on Dec 16, 2021

    @liquid-8
    Member

    Please check what web3py version you use.

  2. PLKuba commented on Dec 16, 2021

    @PLKuba
    ContributorAuthor

    Please check what web3py version you use.

    5.25.0

  3. liquid-8 commented on Dec 17, 2021

    @liquid-8
    Member
  4. PLKuba commented on Dec 18, 2021

    @PLKuba
    ContributorAuthor

    #216 (comment)

    I modified TRANSACTION_DEFAULTS in transactions.py

    TRANSACTION_DEFAULTS = {
        'value': 0,
        'data': b'',
        'gas': lambda web3, tx: web3.eth.estimate_gas(tx),
        'gasPrice': lambda web3, tx: web3.eth.generate_gas_price(tx) or web3.eth.gas_price,
        'maxFeePerGas': Wei(200000),
        'maxPriorityFeePerGas': Wei(200000),
        'chainId': lambda web3, tx: web3.eth.chain_id,
    }
    

    Now it looks like this, but I end up with an error while sending a transaction:

    Traceback (most recent call last):
      File "/Users/kuba/PycharmProjects/Project/playground.py", line 112, in <module>
        spookyswap.make_trade(weth_ftm, dai_ftm, int(amount * 10**18), slippage = 0.2)
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/uniswap/decorators.py", line 29, in approved
        self.approve(token)
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/uniswap/uniswap.py", line 1053, in approve
        tx = self._build_and_send_tx(function)
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/uniswap/uniswap.py", line 1098, in _build_and_send_tx
        return self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/web3/eth.py", line 732, in send_raw_transaction
        return self._send_raw_transaction(transaction)
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/web3/module.py", line 57, in caller
        result = w3.manager.request_blocking(method_str,
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/web3/manager.py", line 198, in request_blocking
        return self.formatted_response(response,
      File "/Users/kuba/PycharmProjects/Project/venv/lib/python3.9/site-packages/web3/manager.py", line 171, in formatted_response
        raise ValueError(response["error"])
    ValueError: {'code': -32000, 'message': 'rlp: expected List'}
    
    
  5. liquid-8 commented on Dec 18, 2021

    @liquid-8
    Member

    Let's try the easier way. Rollback these changes, then here

    def _get_tx_params(self, value: Wei = Wei(0)) -> TxParams:

    change _get_tx_params() to this

    def _get_tx_params(self, value: Wei = Wei(0)) -> TxParams:
            """Get generic transaction parameters."""
            return {
                "type": 0,
                "from": _addr_to_str(self.address),
                "value": value,
                "nonce": max(
                    self.last_nonce, self.w3.eth.get_transaction_count(self.address)
                ),
            }
    
    

    It should work. Otherwise, you'll need to add a couple of lines to this snippet, but I doubt it.

  6. PLKuba commented on Dec 18, 2021

    @PLKuba
    ContributorAuthor

    I rolled back changes and still, I'm getting the same error as initially:

    ValueError: {'code': -32601, 'message': 'the method eth_maxPriorityFeePerGas does not exist/is not available'}
    
  7. liquid-8 commented on Dec 18, 2021

    @liquid-8
    Member

    Ok, then this way

    def _get_tx_params(self, value: Wei = Wei(0)) -> TxParams:
            """Get generic transaction parameters."""
            return {
                "type": 0,
                "from": _addr_to_str(self.address),
                "gas":  Wei(gas_value), #pass it any suitable way
                "gasPrice": Wei(gasPrice_value), #pass it any suitable way
                "value": value,
                "nonce": max(
                    self.last_nonce, self.w3.eth.get_transaction_count(self.address)
                ),
            }
    

    Of course, you may hardcode some values first just to test this snippet. If it still doesn't work, then their devs have made some significant changes.

  8. PLKuba commented on Dec 18, 2021

    @PLKuba
    ContributorAuthor

    EDIT: works fine now. This solved it. Thanks!
    Unfortunately I got an error while signing the transaction : (

  9. jemkein commented on Dec 19, 2021

    @jemkein

    Hi,
    I get the same Error and Tried both solutions.
    #217 (comment) fixes my Problem, the other doesn't.
    But now I get "TypeError: Unknown Transaction type: 0"

    Did you fix your Error while signing the Transaction?

    I am trying to use Pancakeswap (BSC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions