MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
12.04k stars 4.92k forks source link

[Bug]: Error: Transaction reverted: function selector was not recognized and there's no fallback function #14963

Closed PatrickAlphaC closed 2 years ago

PatrickAlphaC commented 2 years ago

Describe the bug

I have created this issue on the hardhat github & the moralis github, and both locations have directed me to metamask instead.

https://github.com/NomicFoundation/hardhat/issues/2708 https://github.com/MoralisWeb3/react-moralis/issues/257

I have a small contract that looks like such:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract FundMe {
    address public s_someAddress;

    constructor(address someAddress) {
        s_someAddress = someAddress;
    }

    function fund() public payable {
        // do stuff
    }
}

That is deployed to the hardhat network. When I call fund from the frontend using ethers, I get the following error in the terminal my hardhat node is running:

eth_call
  Contract call:       <UnrecognizedContract>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512

  Error: Transaction reverted without a reason string
      at <UnrecognizedContract>.<unknown> (0xe7f1725e7734ce288f8367e1bb143e90bb3f0512)
      at HardhatNode.runCall (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:615:20)
      at EthModule._callAction (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:353:9)
      at HardhatNetworkProvider._sendWithLogging (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:139:22)
      at HardhatNetworkProvider.request (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:116:18)
      at JsonRpcHandler._handleRequest (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:188:20)
      at JsonRpcHandler._handleSingleRequest (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:167:17)
      at Server.JsonRpcHandler.handleHttp (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:52:21)

However, if I approve the transaction on the front end, it goes through fine. Any code that I have in the fund function is successful.

What is happening?

I have reset my metamask account several times. Here is how I'm calling this function from the front end:

async function fund() {
  const ethAmount = "0.1"
  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)
    const transactionResponse = await contract.fund({
      value: ethers.utils.parseEther(ethAmount),
    })
  }
}

Steps to reproduce

  1. Clone the repo and install dependencies

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

    yarn hardhat node
  3. Add the hardhat network to your metamask & import one of the private keys from the hardhat nodes output

(Let me know if you need help doing this)

  1. Then, in a new terminal, clone the UI repo, and install dependencies
git clone https://github.com/PatrickAlphaC/nextjs-smartcontract-lottery-fcc
cd nextjs-smartcontract-lottery-fcc
yarn
yarn dev

Go to the UI, and try to hit the Enter Lottery button, and in your terminal, you'll get this issue:

th_call
  Contract call:       <UnrecognizedContract>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512

  Error: Transaction reverted without a reason string
      at <UnrecognizedContract>.<unknown> (0xe7f1725e7734ce288f8367e1bb143e90bb3f0512)
      at HardhatNode.runCall (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:615:20)
      at EthModule._callAction (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:353:9)
      at HardhatNetworkProvider._sendWithLogging (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:139:22)
      at HardhatNetworkProvider.request (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:116:18)
      at JsonRpcHandler._handleRequest (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:188:20)
      at JsonRpcHandler._handleSingleRequest (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:167:17)
      at Server.JsonRpcHandler.handleHttp (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:52:21)

Error messages or log output

th_call
  Contract call:       <UnrecognizedContract>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512

  Error: Transaction reverted without a reason string
      at <UnrecognizedContract>.<unknown> (0xe7f1725e7734ce288f8367e1bb143e90bb3f0512)
      at HardhatNode.runCall (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:615:20)
      at EthModule._callAction (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:353:9)
      at HardhatNetworkProvider._sendWithLogging (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:139:22)
      at HardhatNetworkProvider.request (/DIR/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:116:18)
      at JsonRpcHandler._handleRequest (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:188:20)
      at JsonRpcHandler._handleSingleRequest (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:167:17)
      at Server.JsonRpcHandler.handleHttp (/DIR/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:52:21)

Version

10.14.6

Build type

No response

Browser

Brave

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

brian-tam commented 2 years ago

Hi Patrick I have a similar issue while working on the HTML FundMe app. Is it metamask problem..?

`eth_call Contract call: FundMe# From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 To: 0xe7f1725e7734ce288f8367e1bb143e90bb3f0512

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

RobertoDonPedro commented 2 years ago

I get this error with Hardhat, too. (In my own project, not this sample provided by @PatrickAlphaC) Error: Transaction reverted: function selector was not recognized and there's no fallback function

But it works with Rinkeby...

brian-tam commented 2 years ago

I get this error with Hardhat, too. Error: Transaction reverted: function selector was not recognized and there's no fallback function

But it works with Rinkeby...

Yes once I see it works with Rinkeby and was deployed successfully, I ignore the error and continue the course. I believe it might be the problem of metamask or moralis.. or the integration of both.

BelfordZ commented 2 years ago

If you could please help us by distilling the issue down to having fewer dependencies, it will make it a lot easier to help you track down the source of the issue.

Could you provide a codepen or some small snippets that I can test your issue with?

Thank you for your patience.

PatrickAlphaC commented 2 years ago

Can you click the gitpod button of this repo?

https://github.com/PatrickAlphaC/hardhat-fund-me-fcc

Then run:

yarn hardhat node

Grab a private key from the output and import into metamask - and add the hardhat localhost network to metamask.

Then, gitpod button for this repo:

https://github.com/PatrickAlphaC/html-fund-me-fcc

Spin up the UI, enter a number and select "fund".

BelfordZ commented 2 years ago

It appears your transaction is being reverted. Hardhat/ganache will respond with the Transaction Reverted error immediately, whereas testnets will mine the transaction, and revert can be found by looking at the transaction receipt.

Please double check your smart contract, and check the receipt status of the transaction when you try it on testnet - it likely is also reverting without reason.

If you are still having this issue, pull out the relevant code into the smallest example you can still reproduce the issue with, and post that code back here so that we can get to the bottom of this. I will close the issue for now until the issue is made more clear.

gcedism commented 2 years ago

Hello Patrick, I am not sure if this helps, but if I run everything on a Ganache Local host instead of a Hardhat local node, everything works fine. So the problem might be also something related to the hardhat node (or maybe the interaction between that and Metamask)

PatrickAlphaC commented 2 years ago

Maybe I'm just big dummy. That happens sometimes too.

Thanks all, sorry for the ruckus... I'll see if I can reproduce again...

leonfancy commented 2 years ago

I got the same issue with hardhat node, too.

marcosmartinez7 commented 2 years ago

Same issue with hardhat using useDapp, transaction is successful but hardhat receives invalid calls after that

See the console.log represent the correct behavior, and immediately it receives invalid calls. Maybe metamask is resending some tx?

image
BigTava commented 2 years ago

Same issue here! It happens when I call a function that requires signing the transaction. When I call the same function in the hardhat test environment I have no problems, but through the frontend using metamask, it throws; "Error: Transaction reverted: function selector was not recognized and there's no fallback function at Contract."

sheinix commented 2 years ago

Exactly the same issue here as well. For some reason Metamask interaction with hardhat node goes through but hardhat receives invalid calls

Nitro-lens commented 2 years ago

Has anyone found any solution for this error?

andreupifarre commented 2 years ago

any updates? I am getting the same errors

CamArmstr commented 2 years ago

Also getting a similar error here w/ hardhat and ethers on a local chain.

The transaction will go through fine, it just throws multiple of these error messages

image

mitya-zilbs commented 2 years ago

I am encountering this issue as well, but it seems to me that the transaction is going through because if I console log the transaction hashes, confirmations, and amounts, everything shows up correctly in the console., as well as in my Metamask wallet where all of the transactions and their data are displayed, and the test eth is taken out of the wallet. So I think its just a localhost issue with Hardhat where it posts the response as being reverted before the transaction is confirmed on metamask.

umair-mirza commented 2 years ago

The fix for this issue is pretty simple.

Steps: 1- In your Metamask, for the selected account, Go to Settings. 2- Click on 'Advanced' 3- Click on "Reset Account'

Then try to do the transaction. It will work :)

pacmac0 commented 2 years ago

The fix for this issue is pretty simple.

Steps: 1- In your Metamask, for the selected account, Go to Settings. 2- Click on 'Advanced' 3- Click on "Reset Account'

Then try to do the transaction. It will work :)

Unfortunately for me, it does not fix the issue of the unrecognized selector calls displayed in the console. Is there any progress with this issue? Or anyone has an alternative solution? Could it maybe be due to a newer/incompatible version of moralis, hardhat or so?

developmentWithTariq commented 2 years ago

I am also facing the same issue, have anyone solved it, Error: Transaction reverted: function selector was not recognized and there's no fallback function

pacmac0 commented 2 years ago

I am also facing the same issue, have anyone solved it, Error: Transaction reverted: function selector was not recognized and there's no fallback function

As it was discussed in other issues, this might be an interaction problem within hardhat, metamask or so. I ignored the hardhat node console error for now and moved on. The frontend interaction seems to work anyway and the transactions seem to happen, since number players and so on are being updated. I also hope someone will come up with an explanation for the phenomenon thou.

egvandell commented 2 years ago

It may be obvious, but since I didn't see it mentioned in the thread I thought worth mentioning....that I did some additional testing and noted that if you run a test with a view function instead of a payable function, the error is not generated in the node output, and it operates as expected in this case.

AndyOooh commented 1 year ago

Same issue here. Also, unable to debug. Resolved to the fallback/receive work around.

DrGreeny commented 1 year ago

For me this error was due to a wrong chainId in Metamask. I had some problems with Id: 1337 and used 31337. Metamask was on 1337 still, so after I changed this it worked (also did a reset). Maybe you could check your chainId settings in hardhat and Metamask. Edit: It seems, it just worked once....after I executed the mockOffchain script for performUpkeep, I have now same issue again..

HashHaran commented 1 year ago

I wouldn't be very sure if this is a metamask issue. When I faced this issue, no solution I found online seemed to work. I tried to use anvil, a local Ethereum development node by foundry, in place of hardhat node. This seems to solved the issue for me. I am able to continue my testing in my local node. I believe the issue is somewhere in the metamask and hardhat local node integration.

techybolek commented 1 year ago

Same problem here.

 Contract call:       FundMe#<unrecognized-selector>
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
MemoBaca commented 1 year ago

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

SyedImam1998 commented 1 year ago

Currently, i am facing same issue. Did anyone resolve this issue

image

SyedImam1998 commented 1 year ago

Found something interesting look at here. My first call to setname was successfully done. later 5 calls were made to the contract which all eventually failed but the first call which was succeed changed the state of the contract.

why there is 5more calls happened from meta mask?????

image

MemoBaca commented 1 year ago

@SyedImam1998 Metamask makes a lot of "random" RPC calls. Check this issue and this issue for further reading.

SyedImam1998 commented 1 year ago

@MemoBaca Thanks mate i have added this fallback function now at least this is not throwing error like before:

 fallback() external payable {

    }

image

netzulo commented 1 year ago

If want to protect your users, use this, not payable for fallback calls :D

  /// @dev DON'T give me your money.
  function () external {}
bruce2233 commented 1 year ago

Same issue still

vladimir-byshevets commented 1 year ago

Hello, I have a similar problem 3

vladimir-byshevets commented 1 year ago

Send button not active 2

vladimir-byshevets commented 1 year ago

Here is the function 1

vladimir-byshevets commented 1 year ago

Решил проблему добавлением в файл - hardhat.configю.js код module.exports = { solidity: "0.8.18", networks: { hardhat: { initialBaseFeePerGas: 0, }, }, }; , а так-же добавил в конец кода функцию - fallback() external payable {} Очистил Метамаск, перезапустил hardhat и всё заработало!

nuliknol commented 1 year ago

@vladimir-byshevets by creating a fallback() function you just obfuscated the problem, now all calls (who's methods the contract doesn't implement) go into fallback() where they silently dropped and you never figured out what is the real cause

vladimir-byshevets commented 1 year ago

@vladimir-byshevetsсоздав функцию Fallback(), вы просто запутали проблему, теперь все вызовы (чьи методы не реализуются в контракте) переходят в Fallback(), где они молча удаляются, и вы так и не поняли, в чем настоящая причина

Критикуешь - предлагай!. Если я не правильно сделал, то как правильно?

ayeshaAhmed123 commented 11 months ago

Also getting a similar error here w/ hardhat and ethers on a local chain.

The transaction will go through fine, it just throws multiple of these error messages

image

how did you resolved it ?

tanim0la commented 11 months ago

To resolve this, add a fallback function in your contract:

fallback() external payable {}

nuliknol commented 10 months ago

@vladimir-byshevetsсоздав функцию Fallback(), вы просто запутали проблему, теперь все вызовы (чьи методы не реализуются в контракте) переходят в Fallback(), где они молча удаляются, и вы так и не поняли, в чем настоящая причина

Критикуешь - предлагай!. Если я не правильно сделал, то как правильно?

you can actually setup tcpdump program and sniff all the traffic that is coming over TCP connection (provided plain HTTP is used and not HTTPS) , when I did that I discovered that Metamask is calling decimals() method on the contract when the popup window with transaction details appears to the end User. This is what is causing this error. Obviously Metamask shouldn't do it, but if you want to get rid of this error and have clean hardhat log for debugging purposes you can just declare decimals() in your contract for the time you are developing (and later remove it). Fallback function will just hide all the calls to the contracts that are unsupported and you will have less development power to see what is going on. The other option is to throw Metamask to the trash. @vladimir-byshevets

maoaixiao1314 commented 9 months ago

I also encountered the same problem with the hardhat and metamask versions. I lowered the metamask version to 10.17.0 and the problem was resolved If there are still problems, you need to modify the chain of hardhat, which defaults to 31337. Try changing it to 1337