0

I'm developing a UI for my contract using a local hardhat node with an ethers library. I have several different contract function calls that pass successfully and do not throw any errors in browser console but they do throw an "Error: Transaction reverted: function selector was not recognized and there's no fallback function" in the VSC terminal window that runs the node

Like so:

eth_feeHistory
eth_blockNumber
eth_getBalance (9)
eth_feeHistory
eth_getTransactionCount (2)
eth_sendRawTransaction
  Contract call:       Betting#appendUserBet
  Transaction:         0xb4f3b2277d18a7fcdb26ef6c85c770dd2f03c25d7e197f2a99356ec5d4a9213f
  From:                0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc
  To:                  0x5fbdb2315678afecb367f032d93f642f64180aa3
  Value:               0.427 ETH
  Gas used:            62365 of 62852
  Block #14:           0x9b3b289e7c5ebfc69c223dfcf26effac42bb0485ce75f19d83565e394e32668e

eth_call
  Contract call:       Betting#<unrecognized-selector>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0x5fbdb2315678afecb367f032d93f642f64180aa3

  Error: Transaction reverted: function selector was not recognized and there's no fallback function
      at Betting.<unrecognized-selector> (contracts/Betting.sol:4)
      at HardhatNode.runCall (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:616:20)
      at EthModule._callAction (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:354:9)
      at HardhatNetworkProvider._sendWithLogging (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:139:22)
      at HardhatNetworkProvider.request (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:116:18)
      at JsonRpcHandler._handleRequest (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:188:20)
      at JsonRpcHandler._handleSingleRequest (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:167:17)
      at Server.JsonRpcHandler.handleHttp (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:52:21)

code snippet of a contract with a function in question:

contract Betting {
    uint256 public fee = 1000000000000000000 wei;

    struct UserStruct {
        uint256 betAmount;
        uint256 potentialWinnings;
        string teamChosen;
    }

    mapping(address => UserStruct) public userStructs;
    address[] public userList;


    function appendUserBet(string memory userTeamChosen) public payable {
        uint256 minimumFee = 1 * 10**17 wei;
        userList.push(payable(msg.sender));
        require(msg.value >= minimumFee);
        fee = msg.value;
        userStructs[msg.sender].betAmount += msg.value;
        userStructs[msg.sender].teamChosen = userTeamChosen;
    }
}

snippet of a script that calls this function inside of js:

import { ethers } from "./ethers-5.6.esm.min.js"
import { abi, contractAddress } from "./constants.js"

async function appendUserBet() {
    const ethAmount = document.getElementById("ethAmount").value
    console.log(`Funding with ${ethAmount}...`)
    if (typeof window.ethereum !== "undefined") {
        const provider = new ethers.providers.Web3Provider(window.ethereum)
        const signer = provider.getSigner()
        const contract = new ethers.Contract(contractAddress, abi, signer)
        try {
            const transactionResponse = await await contract.appendUserBet(
                "kek",
                {
                    value: ethers.utils.parseEther(ethAmount)
                }
            )
            await listenForTransactionMine(transactionResponse, provider)
        } catch (error) {
            console.log(error)
        }
    } else {
        appendBetButton.innerHTML = "Please install MetaMask"
    }
}

The contract has other functions but when any of them execute hardhat throws this error even if the execution is 100% successfull. What is wrong with my code? How do I fix this error?

Thanks in advance for your time!

2 Answers 2

0

If anyone ever gets the same problem - just ignore it. I found no solution and code still runs perfectly well.

0

I found a workaround that is working well so far. I ran into the Error: Transaction reverted: function selector was not recognized and there's no fallback function issue just "sometimes", without any apparent reason, and other times, everything worked perfectly. So, I added the retries option to mocha in my hardhat.config file:

  mocha: {
    timeout: 100000000,
    retries: 3,
  },

Hope it helps.

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.