Why do I get the error "Method eth_maxPriorityFeePerGas not supported" when I try to run Web3py with Ganache?
Asked Answered
L

5

32

Running Web3.py with Ganache-cli returns this error:

Method eth_maxPriorityFeePerGas not supported.

However this does work when working with a test-network like Ropsten directly without Ganache-cli.

Running this code in following a tutorial:

from solcx import compile_standard, install_solc
import json
from web3 import Web3
import os
from dotenv import load_dotenv

load_dotenv()

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()

install_solc("0.6.0")

compiled_sol = compile_standard(
    {
        "language": "Solidity",
        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
        "settings": {
            "outputSelection": {
                "*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
            }
        },
    },
    solc_version="0.6.0",
)

with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)

bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
    "bytecode"
]["object"]

abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))
chain_id = 1337
my_address = "0x3d5CDfCea81141d7C839938095912F594b566Ab8"
private_key = os.getenv("private_key")

SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)

nonce = w3.eth.getTransactionCount(my_address)

transaction = SimpleStorage.constructor().buildTransaction(
    {"chainId": chain_id, "from": my_address, "nonce": nonce}
)

signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)

tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)

I get this error in the terminal:

Traceback (most recent call last):
  File "C:\Users\Axceus\Desktop\demos\web3_py_simple_storage\deploy.py", line 54, in <module>
    transaction = SimpleStorage.constructor().buildTransaction(
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\eth_utils\decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\contract.py", line 684, in buildTransaction
    return fill_transaction_defaults(self.web3, built_transaction)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
    return self.func(*args, **kwargs)
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\_utils\transactions.py", line 121, in fill_transaction_defaults
    default_val = default_getter(web3, transaction)
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\_utils\transactions.py", line 71, in <lambda>
    web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\eth.py", line 549, in max_priority_fee
    return self._max_priority_fee()
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "C:\Users\Axceus\AppData\Local\Programs\Python\Python310\lib\site-packages\web3\manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'message': 'Method eth_maxPriorityFeePerGas not supported.', 'code': -32000, 'data': {'stack': 'Error: Method eth_maxPriorityFeePerGas not supported.\n    at GethApiDouble.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\geth_api_double.js:70:16)\n    at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n    at GethDefaults.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\gethdefaults.js:15:12)\n    at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n    at SubscriptionSubprovider.FilterSubprovider.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\subproviders\\filters.js:89:7)\n    at SubscriptionSubprovider.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\subproviders\\subscriptions.js:137:49)\n    at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n    at DelayedBlockFilter.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\delayedblockfilter.js:31:3)\n    at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n    at RequestFunnel.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\requestfunnel.js:32:12)\n    at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n    at Web3ProviderEngine._handleAsync (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:123:3)\n    at Timeout._onTimeout (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:107:12)\n    at listOnTimeout (internal/timers.js:531:17)\n    at processTimers (internal/timers.js:475:7)', 'name': 'Error'}}
Lanneret answered 21/11, 2021 at 4:48 Comment(1)
Use the latest Ganache instead of Ganache-cli: npm install --global ganache. You might need to uninstall the old version with: npm uninstall --global ganache-cli ganache-corePalpitation
S
41

Please use this to send your transaction:

 transaction = SimpleStorage.constructor().buildTransaction( {
    "gasPrice": w3.eth.gas_price, 
    "chainId": chain_id, 
    "from": my_address, 
    "nonce": nonce, 
}
Sharitasharity answered 10/1, 2022 at 17:43 Comment(0)
L
5

By default, web3py will try to create an EIP-1559 transaction. To do so, it will try to fetch the estimated priority fee.

The current stable version of Ganache (6.x) does not support EIP-1559 related functionality, so the RPC call fails. Adding the gas price argument to the transaction will make web3py send a "legacy transaction" (i.e. pre EIP-1559), so it will not try to query the priority fee and simply hard-code the gas price.

From Ganache 7.x (in beta at the time of writing), EIP-1559 transactions will be supported, so the default behavior of web3py will work too.

Leolaleoline answered 5/1, 2022 at 1:3 Comment(0)
C
2
from solcx import compile_standard, install_solc
from web3 import Web3
import json

with open("simpleStorage.sol", "r") as f:
    simple_storage_file = f.read()


# install version of compiler
install_solc("0.6.0")

compiled_sol = compile_standard(
    {
        "language": "Solidity",
        "sources": {"simpleStorage.sol": {"content": simple_storage_file}},
        "settings": {
            "outputSelection": {
                "*": {
                    "*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]
                }
            }
        }
    },
    solc_version = "0.6.0"
)

# print(compiled_sol)



# save the json to file
with open("compile_code.json", "w") as f:
    json.dump(compiled_sol, f)


# get bytecode for deployment
bytecode = compiled_sol["contracts"]["simpleStorage.sol"]["SimpleStorage"]["evm"]["bytecode"]["object"]

# get ABI
abi = compiled_sol["contracts"]["simpleStorage.sol"]["SimpleStorage"]["abi"]


# connect to ganache

# setup RPC SERVER / HTTP provider
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 1337
my_address = "address here"
private_key = "private key here"


SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# print(SimpleStorage)

# nonce >> Number only used once in a cryptographic communication
nonce = w3.eth.getTransactionCount(my_address)
# print(nonce)


transaction = SimpleStorage.constructor().buildTransaction({
    "gasPrice": w3.eth.gas_price, "chainId": chain_id, "from": my_address, "nonce": nonce
})
print(transaction)
Cumbersome answered 3/2, 2022 at 3:6 Comment(0)
A
1

Migrating OP's solution from the question into an answer:

SOLUTION:

 transaction = SimpleStorage.constructor().buildTransaction( {
    "gasPrice": w3.eth.gas_price, 
    "chainId": chain_id, 
    "from": my_address, 
    "nonce": nonce, 
}
Amii answered 21/11, 2021 at 4:48 Comment(0)
S
-1

I've tried to follow Daniel's suggestion but I couldn't install ganache-cli 7.x on my computer for somewhat reason. So I downgrade web3 version to 5.24.0 and it works.

Stagnant answered 5/1, 2022 at 19:1 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewKnack

© 2022 - 2024 — McMap. All rights reserved.