MoralisWeb3 / react-moralis

Hooks and components to use Moralis in a React app
MIT License
623 stars 167 forks source link

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

Open PatrickAlphaC opened 2 years ago

PatrickAlphaC commented 2 years ago

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

Client

paulgs9988 commented 1 year ago

@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 commented 1 year ago

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

Hussainzz commented 1 year ago

@PatrickAlphaC @paulgs9988 anyone has a fix for this ?

usman571 commented 1 year ago

did anybody solve this ? please

MemoBaca commented 1 year ago

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