full-blockchain-solidity-course-py
full-blockchain-solidity-course-py copied to clipboard
Lesson 7: can't end the lottery
Hi,
I'm following the course Solidity, Blockchain, and Smart Contract Course and I cannot pass the test_can_end_lottery test in the development network, I didn't test the other networks.
It looks like I can successfully fund with LINK the lottery contract but the transaction endLottery reverts. I checked all the amounts and fees twice to be sure they have 17 zeros. I pasted below the error, the config, and the function end_lottery().
Error:
LINK funded to contract
LinkToken.transfer confirmed Block: 7 Gas used: 51398 (0.43%)
Transaction sent: 0xe97361a7db515a30e3feac79b1e14d6e16abd3132949b17a82fbb83cd87bc619
Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 7
Lottery.endLottery confirmed (reverted) Block: 8 Gas used: 11813268 (98.44%)
File "brownie/_cli/run.py", line 51, 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/deploy_lottery.py", line 90, in main
end_lottery()
File "./scripts/deploy_lottery.py", line 71, in end_lottery
tx = lottery.endLottery({"from": account})
File "brownie/network/contract.py", line 1710, in __call__
return self.transact(*args)
File "brownie/network/contract.py", line 1583, 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: revert
the brownie-config file includes:
networks:
default: 'development'
development:
keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
fee: 100000000000000000
rinkeby:
vrf_coordinator: '0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B'
eth_usd_price_feed: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e'
link_token: '0x01BE23585060835E02B77ef475b0Cc51aA1e0709'
keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
fee: 100000000000000000
verify: True
mainnet-fork:
eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'
keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
fee: 100000000000000000
and the function end_lottery()
def end_lottery():
account = get_account()
lottery = Lottery[-1]
# to request randomness i need to fund LINK token to the contract/VRFCoordinator so
# 1. I need LINK token in the account
tx = fund_with_link(lottery)
tx.wait(1)
# 2. end the lottery
tx = lottery.endLottery({"from": account})
tx.wait(1)
# wait for the chainlink contract to send the random winner
time.sleep(60)
print(f"{lottery.recentWinner()} is the new winner")
return
I am getting very confused, any idea why this may be happening? Thanks a lot
I'm not sure whats happening with yours but this is what I have saved:
def end_lottery(): account = get_account() lottery = Lottery[-1] # fund the contract # then end the lottery tx = fund_with_link(lottery.address) tx.wait(1) ending_transaction = lottery.endLottery({"from": account}) ending_transaction.wait(1) time.sleep(60) print(f"{lottery.recentWinner()} is the new winner!")
def main(): deploy_lottery() start_lottery() enter_lottery() end_lottery()
Sure
On Wed, Apr 27, 2022, 03:38 snowieoxs @.***> wrote:
I'm not sure whats happening with yours but this is what I have saved:
def end_lottery(): account = get_account() lottery = Lottery[-1]
fund the contract
then end the lottery
tx = fund_with_link(lottery.address) tx.wait(1) ending_transaction = lottery.endLottery({"from": account}) ending_transaction.wait(1) time.sleep(60) print(f"{lottery.recentWinner()} is the new winner!")
def main(): deploy_lottery() start_lottery() enter_lottery() end_lottery()
— Reply to this email directly, view it on GitHub https://github.com/smartcontractkit/full-blockchain-solidity-course-py/issues/1443#issuecomment-1110469637, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUCOXUWBJTDN5YXI3XQAU4DVHCSBFANCNFSM5UJFLB5A . You are receiving this because you are subscribed to this thread.Message ID: <smartcontractkit/full-blockchain-solidity-course-py/issues/1443/1110469637 @github.com>
if you meant that instead of fund_with_link(lottery) I should have fund_with_link(lottery.address), I tested both with the exact same result. The problem anyway appears to be at the transaction endLottery().
Yes, I am getting the same error. I believe it's got something to do with the ChainLink requestRandomness function that is being called inside the end lottery function. I think it's because our contracts don't exactly match with the updated chainlink docs.
Im also getting this error. It has to be something with the changes to the VRF V2.
I'm having the same issue here, did you guys later get this solved?
Me too.
It seems that the function requestRandomness(bytes32 _keyHash, uint256 _fee)
have some changed.
VirtualMachineError: revert
Trace step -1, program counter 2411:
File "C:/Users/chen2/.brownie/packages/smartcontractkit/[email protected]/contracts/src/v0.6/VRFConsumerBase.sol", line 161, in VRFConsumerBase.requestRandomness:
function requestRandomness(bytes32 _keyHash, uint256 _fee)
internal returns (bytes32 requestId)
{
LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PLACEHOLDER));
// This is the seed passed to VRFCoordinator. The oracle will mix this with
// the hash of the block containing this request to obtain the seed/input
// which is finally passed to the VRF cryptographic machinery.
Terminating local RPC client...
I have find the solution!
This error is because we don't give the random address enough Link number.
the latest infomation link show that the 0.25 LINK is needed.
So we need to increase the fee
to 250000000000000000
. Don't forget the function fund_with_link
in helpful_script.py
.