0

I hosted my Lottery website on fleek.co and everything works fine while on hardhat local network. So I decided to test it on Goerli and I'm facing error after error.

At first I got the error 1 below and manually added a gas limit in the hardhat config file. After re-deploying the contract and publishing on fleek, at first, enterRaffle works fine.

When I try to enterRaffle the second time, it fails. Other times it's successful. But even then, it doesn't update the num of players like it's supposed to.

What I'm I missing?

Error 1

Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"code":-32603,"message":"execution reverted","data":{"originalError":{"code":3,"data":"0x1425571c","message":"execution reverted"}}}, method="estimateGas", transaction={"from":"0x13A19933267ec307c96f3dE8Ff8A2392C39263EB","to":"0x5507C7e274B5201a98141cCd0507cF6e4416Be30","value":{"type":"BigNumber","hex":"0x2386f26fc10000"},"data":"0x2cfcc539","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.0)
    at su.makeError (_app-3ca186e4a2557e86.js:1:1975135)
    at su.throwError (_app-3ca186e4a2557e86.js:1:1975255)
    at yh (_app-3ca186e4a2557e86.js:1:2115696)
    at Ad.<anonymous> (_app-3ca186e4a2557e86.js:1:2123240)
    at Generator.throw (<anonymous>)
    at s (_app-3ca186e4a2557e86.js:1:2114235)

Then after adding gas manually like so, error 2 occurs.

        goerli: {
            url: GOERLI_RPC_URL,
            accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [],
            //   accounts: {
            //     mnemonic: MNEMONIC,
            //   },
            saveDeployments: true,
            chainId: 5,
            gas: 6000000,
        },

Error 2

_app-3ca186e4a2557e86.js:1 Uncaught (in promise) Error: transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transactionHash="0x1c28a6b2bfb02f23f443a854c998bec3d965a6beff525f0431480d063e5214c2", transaction={"hash":"0x1c28a6b2bfb02f23f443a854c998bec3d965a6beff525f0431480d063e5214c2","type":2,"accessList":null,"blockHash":null,"blockNumber":null,"transactionIndex":null,"confirmations":0,"from":"0x13A19933267ec307c96f3dE8Ff8A2392C39263EB","gasPrice":{"type":"BigNumber","hex":"0x6bc0e597"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0x6bc0e597"},"gasLimit":{"type":"BigNumber","hex":"0x4c9e58"},"to":"0x5507C7e274B5201a98141cCd0507cF6e4416Be30","value":{"type":"BigNumber","hex":"0x2386f26fc10000"},"nonce":49,"data":"0x2cfcc539","r":"0x3869c8f2e2ecaa492c528f2065d156cdb855a6f2af9669a5472c97473f6f5d74","s":"0x1ae3086d065b24e61c4a01ea1a25a4e1109a809e8a5e8c40fba7a58d8c8e05b2","v":0,"creates":null,"chainId":0}, receipt={"to":"0x5507C7e274B5201a98141cCd0507cF6e4416Be30","from":"0x13A19933267ec307c96f3dE8Ff8A2392C39263EB","contractAddress":null,"transactionIndex":18,"gasUsed":{"type":"BigNumber","hex":"0x6448"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x4cc5aa906cc1a68ef49ade23bec8f679abeb0c2439cc2798d9f5244550bcb8a4","transactionHash":"0x1c28a6b2bfb02f23f443a854c998bec3d965a6beff525f0431480d063e5214c2","logs":[],"blockNumber":7723284,"confirmations":2,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x28a252"},"effectiveGasPrice":{"type":"BigNumber","hex":"0x67d1c29b"},"status":0,"type":2,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.6.0)
    at su.makeError (_app-3ca186e4a2557e86.js:1:1975135)
    at su.throwError (_app-3ca186e4a2557e86.js:1:1975255)
    at Ad.<anonymous> (_app-3ca186e4a2557e86.js:1:2091815)
    at Generator.next (<anonymous>)
    at a (_app-3ca186e4a2557e86.js:1:2072233)

site url

Front-End Repo

Back-End Repo

3 Answers 3

0

In my opinion it has something to do with the enum - it does not reset its state back to OPEN ( which I see happens in the fulfillrandomwords() function.

My 2 suggestions:

  1. Make sure that the contract is linked to a subscription with enough test LINK in it
  2. It may also be dues to rounding the randomWords number with the modulo.In the fullfillRandomWords() function, at line 154 , you may try changing it to:
       uint256 indexOfWinner = (randomWords[0] % s_players.length)*1 ;

I hope some of this helps.

1
  • Hello @petar, I appreciate you taking time to help. I don't think the issue is with getting a random number and picking a winner. The error occurs when entering players in the raffle. And it's only occurring on Goerli testnet. Locally everything works fine.
    – kihiuFrank
    Oct 9, 2022 at 13:57
0

Gas estimation is being done by running the code virtually. And if the code gives an error, the application cannot estimate the gas. Even if you manually set the gas and still call the function, this time it will work on evm and will still be a failed transaction.

In your case if the app gives "Error: cannot estimate gas" when you call enterRaffle either if the RaffleState is not Open at the time of call or amount is less then i_enteranceFee.

2
  • Much appreciation for taking your time to help. @Yetik Here are my observations. I removed the manual gas input in the hardhat config. On goerli, after clicking Enter Raflle button, it throws the Error: cannot estimate gas; transaction may fail or may require manual gas limit error, without even opening metamask. The entrance fee is 0.01 ETH and my wallet balance is more than that. When I add gas manually the transaction is succesful the first time before failing in the 2nd attempt to enter the lottery.
    – kihiuFrank
    Oct 9, 2022 at 14:27
  • And if the raffle state is not open, I would expect a different error message. Why would it be open locally but not while on the testnet?
    – kihiuFrank
    Oct 9, 2022 at 14:27
0

Had forgotten to write an update here. So, I noticed something;

The issue was with the ABI.

When I deploy, hh deploy --network goerli The abi looks like this one below; (this works fine)

{
        "type": "function",
        "name": "getNumWords",
        "constant": true,
        "stateMutability": "pure",
        "payable": false,
        "inputs": [],
        "outputs": [{ "type": "uint256" }]
    },

When I quit my local hardhat node and spin it up again, ```hh node`` The abi (in constants folder), updates itself to this; (that's where the gas field is added);

{
        "type": "function",
        "name": "getLastestTimeStamp",
        "constant": true,
        "stateMutability": "view",
        "payable": false,
        "gas": 29000000,           // here
        "inputs": [],
        "outputs": [{ "type": "uint256" }]
    },

I don't know why rerunning the node changes the abi, but after running with the correct ABI, everything works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.