react-moralis icon indicating copy to clipboard operation
react-moralis copied to clipboard

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

Open PatrickAlphaC opened this issue 3 years ago • 5 comments
trafficstars

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

PatrickAlphaC avatar Jun 13 '22 23:06 PatrickAlphaC

@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

paulgs9988 avatar Nov 12 '22 14:11 paulgs9988

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

PatrickAlphaC avatar Nov 14 '22 17:11 PatrickAlphaC

@PatrickAlphaC @paulgs9988 anyone has a fix for this ?

Hussainzz avatar Dec 10 '22 04:12 Hussainzz

did anybody solve this ? please

usman571 avatar Jan 17 '23 13:01 usman571

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

MemoBaca avatar Feb 11 '23 03:02 MemoBaca