Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Transaction reverted: function selector was not recognized and there's no fallback function #257

Open
3 tasks done
PatrickAlphaC opened this issue Jun 13, 2022 · 5 comments

Comments

@PatrickAlphaC
Copy link

PatrickAlphaC commented Jun 13, 2022

New Bug Report

Checklist

Issue Description

Steps + code to reproduce

git clone https://github.com/PatrickAlphaC/hardhat-smartcontract-lottery-fcc
cd hardhat-smartcontract-lottery-fcc
yarn
yarn hardhat node

Then, in another terminal

git clone https://github.com/PatrickAlphaC/nextjs-smartcontract-lottery-fcc
cd nextjs-smartcontract-lottery-fcc
yarn
yarn dev

Go to the UI created at http://localhost:3000, and go into your wallet and add the hardhat network:

Name: Hardhat-Localhost
RPC URL: http://127.0.0.1:8545/
Chain ID: 31337
Currency: ETH

Then, go to import accounts and add one of the private keys the hardhat node gave you.

On http://localhost:3000, hit the enter raffle button, and you'll see the error in your hardhat terminal. However, the contract clearly has an enterRaffle function.

In our react code, we use the runContractFunction hook like so:

const {
        runContractFunction: enterRaffle,
        data: enterTxResponse,
        isLoading,
        isFetching,
    } = useWeb3Contract({
        abi: abi,
        contractAddress: raffleAddress,
        functionName: "enterRaffle",
        msgValue: entranceFee,
        params: {},
    })

And call it in a button:

                    <button
                        className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded ml-auto"
                        onClick={async () =>
                            await enterRaffle({
                                // onComplete:
                                // onError:
                                onSuccess: handleSuccess,
                                onError: (error) => console.log(error),
                            })
                        }
                        disabled={isLoading || isFetching}
                    >
                        {isLoading || isFetching ? (
                            <div className="animate-spin spinner-border h-8 w-8 border-b-2 rounded-full"></div>
                        ) : (
                            "Enter Raffle"
                        )}
                    </button>

Actual Outcome

eth_call
  Contract call:       Raffle#<unrecognized-selector>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9

  Error: Transaction reverted: function selector was not recognized and there's no fallback function
      at Raffle.<unrecognized-selector> (contracts/Raffle.sol:20)
      at HardhatNode.runCall (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:615:20)
      at EthModule._callAction (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:353:9)
      at HardhatNetworkProvider._sendWithLogging (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:139:22)
      at HardhatNetworkProvider.request (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:116:18)
      at JsonRpcHandler._handleRequest (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:188:20)
      at JsonRpcHandler._handleSingleRequest (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:167:17)
      at Server.JsonRpcHandler.handleHttp (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:52:21)

eth_call
  Contract call:       Raffle#<unrecognized-selector>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9

  Error: Transaction reverted: function selector was not recognized and there's no fallback function
      at Raffle.<unrecognized-selector> (contracts/Raffle.sol:20)
      at HardhatNode.runCall (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:615:20)
      at EthModule._callAction (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:353:9)
      at HardhatNetworkProvider._sendWithLogging (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:139:22)
      at HardhatNetworkProvider.request (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:116:18)
      at JsonRpcHandler._handleRequest (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:188:20)
      at JsonRpcHandler._handleSingleRequest (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:167:17)
      at Server.JsonRpcHandler.handleHttp (/DIR/hardhat-smartcontract-lottery-fcc/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:52:21)

Expected Outcome

The transaction does not error

Environment

Server

  • Moralis server version: NONE

Client

  • react-moralis version: 1.4.0
  • Moralis SDK version: 1.8.0
  • Operating system: Mac OS
  • Browser: Brave
@paulgs9988
Copy link

@PatrickAlphaC , I'm a big fan of yours and appreciate all you do. I'm working on a project unrelated to this and am getting a similar error. My setup is very similar to yours and my application was working fine until I started trying to add another chain. Now, no matter what I do, even undoing all changes, I am getting the same error you describe:

eth_call
  Contract call:       Escrow#<unrecognized-selector>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512

  Error: Transaction reverted: function selector was not recognized and there's no fallback function
      at Escrow.<unrecognized-selector> (contracts/Escrow.sol:12)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

It seems like some issue with Hardhat, but I've been fiddling around with it for a few days now and cannot find a solution. I was wondering if you found an easy one

@PatrickAlphaC
Copy link
Author

@Y0moo any thoughts on the above? A few people have run into this.

@Hussainzz
Copy link

@PatrickAlphaC @paulgs9988 anyone has a fix for this ?

@usman571
Copy link

did anybody solve this ? please

@MemoBaca
Copy link

@usman571 smartcontractkit/full-blockchain-solidity-course-js#315 (comment) explains the issue and how to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants