Lesson 7: Gas Estimation Error when Ending Lottery #1669
-
ProblemI was working with the Lottery contract and everything went successful when I deployed to a Local Chain. The issue started with the testnet. The contract gives a Gas Estimation Error when the I know that my contract must have LINK before it can call that randomness function. I do call the I would really appreciate any help! Thanks! Error1 LINK TransferCodeHere is the def end_lottery():
acc = get_acc()
lottery = Lottery[-1]
print(f"Balance of this contract before funding: {lottery.balance()}")
tx = fund_with_link(lottery.address)
tx.wait(1)
print(f"Balance of this contract: {lottery.balance()}")
tx = lottery.endLottery({"from": acc})
tx.wait(1)
time.sleep(60)
winner_address = lottery.last_winner()
print(
f"Winner Address is: {winner_address} with Name: {lottery.player_names(winner_address)}"
)
LINK_AMOUNT = 1000000000000000000
def fund_with_link(contract_address, acc=None, link_token=None, amount=LINK_AMOUNT):
if acc:
acc = acc
else:
acc = get_acc()
if link_token:
link_token = link_token
else:
link_token = get_contract("link-token")
# 7.43.48 Interface working example to replace Line 55
# link_token_contract = interface.LinkTokenInterface(link_token.address)
tx = link_token.transfer(contract_address, amount, {"from": acc})
tx.wait(1)
print(f"Contract Funded with Link")
return tx function endLottery() public {
state = LOTTERY_STATE.running;
bytes32 requestID = requestRandomness(keyHash, fee); //This will return a bytes32 requestID
emit requested_randomness(requestID);
//This is done so that the request ID is emitted onthe blockchain node as an event that we can access
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hello @abdullahpichoo Also, I highly recommend to delete the build folder, and re-deploy the contract.. then try again. Please let us know if this was helpful. |
Beta Was this translation helpful? Give feedback.
Hello @abdullahpichoo
Tricky question, but thanks for the detailed explanation of the error this is really helpful.
So I would say there is not taking one of the contracts correctly, be sure the name of
link-token
is setup the same for the network you are deploying to on yourbrownie-config.yaml
and that yourget_ contract
function is correct.Also, I highly recommend to delete the build folder, and re-deploy the contract.. then try again.
Please let us know if this was helpful.