I am going through brownie_fund_me part of this course:
https://github.com/PatrickAlphaC/brownie_fund_me
The initial deploy,.py works properly, but I keep getting some variation of invalid opcode and the transaction keeps reverting when I try to deploy to ganache-local. I am able to run the tests in this project to development/ganache-cli but fail with ganache-local and Rinkeby.
Expected Behavior
Contract should deploy fund and withdraw properly with Ganache UI.
Current Behavior
Running `brownie run deploy.py --network ganache-local. I get these errors while running or troubleshooting.
- ValueError: Gas estimation failed: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.
- ValueError: Execution reverted during call: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, include
allow_revert:True
as a transaction parameter. - VirtualMachineError: invalid opcode: invalid opcode
Steps to reproduce & Troubleshooting
Git clone
https://github.com/PatrickAlphaC/brownie_fund_me
brownie compile -a. Compiles successfully.
Solc version: 0.6.12
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
Generating build data...
- smartcontractkit/[email protected]/AggregatorInterface
- smartcontractkit/[email protected]/AggregatorV2V3Interface
- smartcontractkit/[email protected]/AggregatorV3Interface
- smartcontractkit/[email protected]/SafeMathChainlink
- FundMe
- MockV3Aggregator
Project has been compiled. Build artifacts saved at /Users/davidandrews/Documents/Projects/Web3/bss/build/contracts
- Deploy ganache ui with default gas limit and values.
- Execute
brownie run scripts/deploy.py --network ganache-local
~/Documents/Projects/Web3/brownie_fund_me (main●●)$ brownie run scripts/deploy.py --network ganache-local
Brownie v1.17.1 - Python development framework for Ethereum
brownie_fund_me is the active project.
Running 'scripts/deploy.py::main'...
The active network is ganache-local
Deploying Mocks...
Transaction sent: 0xe7b501480f70836256dbdd37a159100198d1422897117777e33588d1b2e1a566
Gas price: 20.0 gwei Gas limit: 540226 Nonce: 0
MockV3Aggregator.constructor confirmed Block: 1 Gas used: 491115 (90.91%)
MockV3Aggregator deployed at: 0xF5F2B13A72901f1621d2CD9b382c1c513ac0724D
Mocks Deployed!
Transaction sent: 0xc5a26f42997e9c648ee4d12df1805746cd3ca6508c315747f9b836ce5fb39516
Gas price: 20.0 gwei Gas limit: 528696 Nonce: 1
FundMe.constructor confirmed Block: 2 Gas used: 480633 (90.91%)
FundMe deployed at: 0xEDa314a434Ef759d85F60a54804FdfdbEB26F179
Contract deployed to 0xEDa314a434Ef759d85F60a54804FdfdbEB26F179
- Execute:
brownie run scripts/fund_and_withdraw.py --network ganache-local
BssProject is the active project.
Running 'scripts/fund_and_withdraw.py::main'...
25000000000000000
The current entry fee is 25000000000000000
Funding
Transaction sent: 0xffd686e74b439f0afff97ba5ab77ce31a48a66a6f2710d123b3cf37bc8b8bade
Gas price: 20.0 gwei Gas limit: 94207 Nonce: 2
FundMe.fund confirmed Block: 3 Gas used: 85643 (90.91%)
File "brownie/_cli/run.py", line 50, in main
return_value, frame = run(
File "brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/fund_and_withdraw.py", line 23, in main
withdraw()
File "./scripts/fund_and_withdraw.py", line 18, in withdraw
fund_me.withdraw({"from": account})
File "brownie/network/contract.py", line 1625, in __call__
return self.transact(*args)
File "brownie/network/contract.py", line 1498, in transact
return tx["from"].transfer(
File "brownie/network/account.py", line 644, in transfer
receipt, exc = self._make_transaction(
File "brownie/network/account.py", line 727, in _make_transaction
raise VirtualMachineError(e) from None
File "brownie/exceptions.py", line 121, in __init__
raise ValueError(str(exc)) from None
ValueError: Gas estimation failed: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.
- Change gas_limit param to default Ganache UI gas_limit:
fund_me.withdraw({"from": account})
->fund_me.withdraw({"from": account, 'gas_limit': 6721975})
and runfund_and_withdraw.py.
Brownie v1.17.1 - Python development framework for Ethereum
BssProject is the active project.
Running 'scripts/fund_and_withdraw.py::main'...
25000000000000000
The current entry fee is 25000000000000000
Funding
Transaction sent: 0x996f97219b9c8cf1dd3f88753adf4c94335d27d1784972b976c550cea5f13c6d
Gas price: 20.0 gwei Gas limit: 61207 Nonce: 3
FundMe.fund confirmed Block: 4 Gas used: 55643 (90.91%)
File "brownie/_cli/run.py", line 50, in main
return_value, frame = run(
File "brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/fund_and_withdraw.py", line 24, in main
withdraw()
File "./scripts/fund_and_withdraw.py", line 19, in withdraw
fund_me.withdraw({"from": account, 'gas_limit': 6721975})
File "brownie/network/contract.py", line 1625, in __call__
return self.transact(*args)
File "brownie/network/contract.py", line 1498, in transact
return tx["from"].transfer(
File "brownie/network/account.py", line 644, in transfer
receipt, exc = self._make_transaction(
File "brownie/network/account.py", line 752, in _make_transaction
exc = VirtualMachineError(e)
File "brownie/exceptions.py", line 121, in __init__
raise ValueError(str(exc)) from None
ValueError: Execution reverted during call: 'execution reverted: VM Exception while processing transaction: invalid opcode'. This transaction will likely revert. If you wish to broadcast, include `allow_revert:True` as a transaction parameter.
- Added
fund_me.withdraw({"from": account, 'gas_limit': 6721975, 'allow_revert': True})
Brownie v1.17.1 - Python development framework for Ethereum
BrownieFundMeProject is the active project.
Running 'scripts/fund_and_withdraw.py::main'...
25000000000000000
The current entry fee is 25000000000000000
Funding
Transaction sent: 0x1709a9bb9cf6213526c0307eb01c91c00a644a227c8a0efffa71310f3b94a106
Gas price: 20.0 gwei Gas limit: 61207 Nonce: 4
FundMe.fund confirmed Block: 5 Gas used: 55643 (90.91%)
FundMe.fund confirmed Block: 5 Gas used: 55643 (90.91%)
Transaction sent: 0x5e4947dc2d642dbb337eefdb6711c33b39eca70e2294aed10c05e3d15861b3a2
Gas price: 20.0 gwei Gas limit: 6721975 Nonce: 5
FundMe.withdraw confirmed (invalid opcode) Block: 6 Gas used: 6721975 (100.00%)
File "brownie/_cli/run.py", line 50, in main
return_value, frame = run(
File "brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/fund_and_withdraw.py", line 28, in main
withdraw()
File "./scripts/fund_and_withdraw.py", line 21, in withdraw
tx = fund_me.withdraw({"from": account, 'gas_limit': 6721975, 'allow_revert': True})
File "brownie/network/contract.py", line 1625, in __call__
return self.transact(*args)
File "brownie/network/contract.py", line 1498, in transact
return tx["from"].transfer(
File "brownie/network/account.py", line 682, in transfer
receipt._raise_if_reverted(exc)
File "brownie/network/transaction.py", line 446, in _raise_if_reverted
raise exc._with_attr(
VirtualMachineError: invalid opcode: invalid opcode
- I am also deleting build artifacts between runs.
- I've tried this:
delete ganache-local from your brownie networks list
delete the corresponding folders on build/deployments/1337(or whatever your chainID was) as well as the corresponding chainid lines of the map.json file
on your Ganache instance, instead of clicking on the quicklaunch, click on create workspace
Set up the gas limit to a higher number than it is currently at (I chose 8000000), the rest can stay as it is
on your VSC terminal, or whatever program you use to type your code, re-introduce the network ganache-local (brownie networks add Ethereum ganache-local host=http://YOURHOSTNUMBER chainid=YOURCHAINID
I've tried setting the gas_limit in ganache ui to 999999999999999 and gas price to gwei.
Possible Solution
This appears to be a gas estimation and gas price issue with Ganache UI.
Context
I'm trying to complete this course: https://github.com/smartcontractkit/full-blockchain-solidity-course-py#lesson-6-brownie-fund-me
Your Environment
- Python 3.9.8
- Ganache version:
Ganache CLI v6.12.2 (ganache-core: 2.13.2)
RPC Server:HTTP://127.0.0.1:7545 chainid=1377
- Ganache UI version:
Version 2.5.4 (2.5.4.1367)
- Node version:
v16.8.0
- Operating System and version:
macOS Monterey 12.1 Beta
- Truffle version:
Truffle v5.4.21
- Link to your project:
https://github.com/PatrickAlphaC/brownie_fund_me
. I've cloned this repo to make sure I didn't have a bug in my own code.