PatrickAlphaC / smartcontract-lottery

MIT License
79 stars 113 forks source link

Gas estimation failed #85

Closed yasinahmed81 closed 1 year ago

yasinahmed81 commented 1 year ago

Hello,

When I run the completed project on the Goerli testnet, I am getting a gas estimation failed error, please see below:

brownie run ./scripts/deploy_lottery.py --network goerli
Brownie v1.19.2 - Python development framework for Ethereum

SmartcontractLotteryProject is the active project.

Running 'scripts/deploy_lottery.py::main'...
Transaction sent: 0x42ace8420f02ad48f9da38fac2c940b59a359860a90a08a68396954b1e6cc439
  Gas price: 42.387398784 gwei   Gas limit: 1005105   Nonce: 81
  Lottery.constructor confirmed   Block: 8272125   Gas used: 913732 (90.91%)
  Lottery deployed at: 0xaa3d31cea2A39d1c1AEd1cE26B7930e81713F5cb

Waiting for https://api-goerli.etherscan.io/api to process contract...
Verification submitted successfully. Waiting for result...
Verification complete. Result: Pass - Verified
Lottery has been deployed!
Transaction sent: 0x37923fd5289e0e6956149ffffea98f3985b7676e0e99ab8431979f0dc0298bf5
  Gas price: 37.839871559 gwei   Gas limit: 31572   Nonce: 82
  Lottery.startLottery confirmed   Block: 8272129   Gas used: 28702 (90.91%)

  Lottery.startLottery confirmed   Block: 8272129   Gas used: 28702 (90.91%)

Lottery has started!
Transaction sent: 0xcc84bf69a1ea21d745dd5df8a2c2bf3ad8e0a5ee87e62042876d94c5e0cea5f0
  Gas price: 35.458648423 gwei   Gas limit: 97461   Nonce: 83
  Lottery.enter confirmed   Block: 8272131   Gas used: 88601 (90.91%)

  Lottery.enter confirmed   Block: 8272131   Gas used: 88601 (90.91%)

You have entered the lottery!
Transaction sent: 0xc69108e2ce1665a762bea307b4bc5dd9e115d8a943d30596ec132e244678641f
  Gas price: 34.120767832 gwei   Gas limit: 56986   Nonce: 84
  LinkToken.transfer confirmed   Block: 8272133   Gas used: 51806 (90.91%)

  LinkToken.transfer confirmed   Block: 8272133   Gas used: 51806 (90.91%)

Funded contract!
  LinkToken.transfer confirmed   Block: 8272133   Gas used: 51806 (90.91%)

  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 110, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/deploy_lottery.py", line 63, in main
    end_lottery()
  File "./scripts/deploy_lottery.py", line 49, in end_lottery
    ending_transaction = lottery.endLottery(
  File "brownie/network/contract.py", line 1864, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1737, 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 93, in __init__
    raise ValueError(str(exc)) from None
ValueError: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

Anyone know how to fix this?

Thanks in advance.

PatrickAlphaC commented 1 year ago

Hmm.... VRFv1 likely doesn't work on goerli. We'd have to use VRFv2...

yasinahmed81 commented 1 year ago

Thanks Patrick.

yasinahmed81 commented 1 year ago

For those working on this project on the Goerli network, ensure your config looks like so:

goerli:
    vrf_coordinator: "0x2bce784e69d2Ff36c71edcB9F88358dB0DfB55b4"
    link_token: "0x326C977E6efc84E512bB9C30f76E30c160eD06FB"
    keyhash: "0x0476f9a745b61ea5c0ab224d3a6e4c99f0b02fce4da01143a4f70aa80ae76e8a"
    fee: 300000000000000000 # 0.3
    eth_usd_price_feed: '0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e'
    verify: True
yasinahmed81 commented 1 year ago

@PatrickAlphaC VRFv1 does actually work with Goerli, I just had my config setup with different vrf_ccordinator and keyhash values which I took from here.

But I saw that from your NFT-Demo project the config was different, and when I used those settings back in this project, it worked!