My enter lottery function which charges 5 dollars won't transact successfully when I deploy it with brownie. It works fine on remix, but when i try making a script file to run it it keeps sending the error
ValueError: Gas estimation failed: 'execution reverted: VM Exception while processing
transaction: revert'. This transaction will likely revert. If you wish to broadcast, you
must set the gas limit manually.
At first I tried creating a separate script file to run it but it send that error.I tried running it in my deploy script but it still doesn't work.
My deploy script
from brownie import lottery, accounts, config, network,
MockV3Aggregator, LinkToken, VRFCoordinatorMock
from scripts.helpful import get_account, deploy_mocks,
LOCAL
from web3 import Web3
value = Web3.toWei(0.04, "ether")
def deploy_txn():
account = get_account()
print(f"owner is {account}")
print(f"{network.show_active()} is the current network")
if network.show_active() not in LOCAL:
pfaddress = config[network.show_active()]["padress"]
vrf = config[network.show_active()]["vrf"]
link = config[network.show_active()]["link_token"]
keyhash = config[network.show_active()]["keyhash"]
fee = config[network.show_active()]["fee"]
else:
deploy_mocks()
pfaddress = MockV3Aggregator[-1].address
vrf = VRFCoordinatorMock[-1].address
link = LinkToken[-1].address
keyhash = '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
fee = '100000000000000000'
caddr = lottery.deploy(vrf, pfaddress, link, keyhash, fee, {"from": account})
print(caddr)
def start_lottery():
account = get_account()
lottery[-1].startLottery({"from": account})
def enter_lottery():
account = get_account()
lottery[-1].enter({"from": account, "value": value})
def main():
deploy_txn()
start_lottery()
enter_lottery()
My solidity enterLottery function
function enter() payable public {
require(ETHtoUSD(msg.value) >= usdfee, "Not enough ETH!");
require(currentstate == lotteryState.open, "Lottery isn't open yet!");
players.push(payable(msg.sender));
}
the usdfee is $5 and I funded it with 0.04ETH($64)