I kind of accidentally deployed an ERC20 token contract on the mainnet and brownie didn't even ask me to confirm so I ended up spending $700+ worth of ETH to practice. I didn't think it would cost that much and for some reason brownie didn't ask me for permission like metamask usually does to confirm that I'm ok with the transaction fees. How can I avoid this or atleast confirm that I'm ok with transaction fees with eth-brownie? Should I programmatically check if I'm ok with the transaction fee associated with a given transaction, if so best way to go about that? Should I be focused on gas limit? Should I set a gas limit on each transaction? Also how do I see the estimated gas for a transaction with eth-brownie?


2 Answers 2


Got on track by this blog post :

from brownie import accounts, web3, MyContract

account = accounts.load("my_account")

contract = MyContract.deploy({"from": account})
# contract = MyContract[len(MyContract)-1] # if contract is already deployed

mocked = web3.eth.contract(
           address = contract.address,
           abi = contract.abi

estimated_gas = mocked.functions \
                      .functionToBeTested(function_payload) \
                      .estimateGas({"from": account.address})


BTW, you can retrieve the current gas price with


and the latest block average gas limit with

last_block = web3.eth.getBlock("latest")
gas_limit = last_block.gasLimit / (len(last_block.transactions) if last_block.transactions else 1)
  • For search's sake, in my case I encountered execution reverted: ERC721: mint to the zero address error because I missed the estimateGas() arguments. Commented Jan 28, 2022 at 17:52

Skippys' answer is the correct one, i will put another implementation here in case anyone wants to know: P.S: here is the complete walk through link

from web3 import Web3, HTTPProvider
import statistics
pending_transactions = web3.provider.make_request("parity_pendingTransactions", [])
gas_prices = []
gases = []
for tx in pending_transactions["result"[:10]]:

print("gasPrice: ", statistics.mean(gas_prices))
print(" ")
print("gasPrice: ", statistics.median(gas_prices))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.