【问题标题】:Smart Contract Lottery throws "VirtualMachineError: revert" when ending the lottery智能合约彩票在结束彩票时抛出“VirtualMachineError:revert”
【发布时间】:2021-12-29 18:53:40
【问题描述】:

我一直在关注 Solidity、区块链和智能合约课程 - 从初学者到专家 Python 教程 (https://www.youtube.com/watch?v=M576WGiDBdQ&t=28658s)。当我运行 deploy_lottery.py 时,它会在结束抽奖时崩溃。这是 Lottery.sol 中代码的 sn-p

function endLottery() public onlyOwner {
        lottery_state = LOTTERY_STATE.CALCULATING_WINNER;
        bytes32 requestId = requestRandomness(keyhash, fee);

        emit RequestedRandomness(requestId);
    }

这是 deploy_lottery.py 中的代码 sn-p

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)
    print("Here")
    ending_transaction = lottery.endLottery({"from": account})
    print("ended transaction")
    ending_transaction.wait(1)
    time.sleep(180)
    print(f"{lottery.recentWinner()} is the new winner!")

我还附上了错误快照。提前致谢。 https://i.stack.imgur.com/yU8jC.png

【问题讨论】:

  • 你使用的是 GitHub 的原始代码吗?
  • 我也有同样的问题!
  • 不,我跟着 Patrick 在视频中编码。我还逐行检查了所有 github 文件。

标签: solidity smartcontracts chainlink brownie


【解决方案1】:

我遇到了同样的错误。解决方案是用足够的代币为合同提供资金。为了测试我做了 金额=5000000000000000000 in fund_with_link()

【讨论】:

  • 'def fund_with_link(contract_address, account=None, link_token=None, amount=5000000000000000000): account = account if account else get_account() link_token = link_token if link_token else get_contract("link_token") tx = link_token.transfer(contract_address, amount, {"from": account}) tx.wait(1) print("Contract Funded") return tx '
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多