12

I'm trying to call a function[propose] from Openzeppelin governor.sol. The function is like this...

function propose(
        address[] memory targets,
        uint256[] memory values,
        bytes[] memory calldatas,
        string memory description
    ) public virtual override returns (uint256) {
        require(
            getVotes(msg.sender, block.number - 1) >= proposalThreshold(),
            "GovernorCompatibilityBravo: proposer votes below proposal threshold"
        );

        uint256 proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));

        require(targets.length == values.length, "Governor: invalid proposal length");
        require(targets.length == calldatas.length, "Governor: invalid proposal length");
        require(targets.length > 0, "Governor: empty proposal");

        ProposalCore storage proposal = _proposals[proposalId];
        require(proposal.voteStart.isUnset(), "Governor: proposal already exists");

        uint64 snapshot = block.number.toUint64() + votingDelay().toUint64();
        uint64 deadline = snapshot + votingPeriod().toUint64();

        proposal.voteStart.setDeadline(snapshot);
        proposal.voteEnd.setDeadline(deadline);

        emit ProposalCreated(
            proposalId,
            _msgSender(),
            targets,
            values,
            new string[](targets.length),
            calldatas,
            snapshot,
            deadline,
            description
        );

        return proposalId;
    }

I've used this function in my different contract like this...

function propose(
    address[] memory targets,
    uint256[] memory values,
    bytes[] memory calldatas,
    string memory description
  ) public override(Governor, IGovernor) returns (uint256) {
    return super.propose(targets, values, calldatas, description);
  }

finally, after successfully deploying it and when it comes to using it for a function proposal, I'm using the Box.sol's store function to govern on.

// Stores a new value in the contract
  function store(uint256 newValue) public onlyOwner {
    value = newValue;
    emit ValueChanged(newValue);
  }

First I made the, function selector like this...

const governor = await ethers.getContract("GovernorContract");
const box = await ethers.getContract("Box");

const encodedFunctionCall = box.interface.encodeFunctionData('store', [77]);

and on consoling, I'm getting this selector in bytes...

0x6057361d000000000000000000000000000000000000000000000000000000000000004d

Now, I'm calling the propose function...

const proposeTx = await governor.propose(
        [box.address],
        [0],
        [encodedFunctionCall],
        proposalDescription
    );

But here, I'm getting the error...

Error: Transaction reverted: function selector was not recognized and there's no fallback function
      at Box.<unrecognized-selector> (contracts/Box.sol:6)

Actually, it is not recognizing the store function of box.sol. I've already compiled the contract many time, but getting the same error.

3
  • Have you tried running on Remix? maybe the function you are calling might be missing in the ABI array. Mar 20, 2022 at 8:57
  • Bilal, it works fine on Remix. By the way, I also consoled the "Box.interface", and I can smell that ABI is fine.
    – Adil Nehal
    Mar 20, 2022 at 13:57
  • I got the same selector you did, and mine is working fine... not sure where this is going wrong. Apr 28, 2022 at 23:00

8 Answers 8

5

Reset the metamask account. I have got same problem and after reset it solved

1
  • 2
    I still get the same error in hardhat console after I reset Metamask. Nov 13, 2022 at 0:18
1

It seems that Metamask is likely sending multiple requests. Sometimes, while you may see those errors the first txn is actually going through fine. I tested this with my local hardhat and was able to write and read from the local chain.

You can refer the Github issue for more info, specifically this comment.

0

I got this error when running this on the hardhat network. Once I switched to a real network like kovan it worked. If you're hitting this error try running against a real network.

0

I also encountered this problem when debugging solidity using metamask, and later I added methods fallback function and receive function to my solidity smart contract code, and it was fine.

 fallback() external payable {
        console.log("----- fallback:", msg.value);
    }

    receive() external payable {
        console.log("----- receive:", msg.value);
    }

when i add above code in my solidity code, Hardhat node log is fine:

eth_sendRawTransaction
      Contract call:       <UnrecognizedContract>
      Transaction:         0x1c6567d6d7f1e19589927efbb0ca338cc6d6b13cc4db3b90c0b8c2b3dd23eb46
      From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
      To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
      Value:               5 ETH
      Gas used:            104466 of 104466
      Block #4:            0x8cfb9487a2d82688cec57d211837797eda789c7cc13881f2eaefef4d59a72968
    
    eth_feeHistory (2)
    eth_getTransactionReceipt
    eth_blockNumber
    eth_getTransactionReceipt
    eth_getBlockByHash
    eth_call
      Contract call:       <UnrecognizedContract>
      From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
      To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
    
      console.log:
        ----- fallback: 0
    
    eth_call
      Contract call:       <UnrecognizedContract>
      From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
      To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
    
      console.log:
        ----- fallback: 0
    
    eth_call
      Contract call:       <UnrecognizedContract>
      From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
      To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
    
      console.log:
        ----- fallback: 0
    
    eth_call
      Contract call:       <UnrecognizedContract>
      From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
      To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
    
      console.log:
        ----- fallback: 0
    
    eth_call
      Contract call:       <UnrecognizedContract>
      From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
      To:                  0xe7f1725e7734ce288f8367e1bb143e90bb3f0512
    
      console.log:
        ----- fallback: 0

I think maybe metamask call the eth node many times, But not let me know.

1
  • Not sure why this was downvoted, It is a legitimate cause for getting OP's error if the contract is calling another contract that will try to transfer ETH to it.
    – GnP
    Oct 8 at 16:32
0

According to the git hub issue that Vivek has pointed out this has been categorized as a metamask issue. However 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.

0

I got this error when calling the contract through the interface that was not supported by the last one. So check the interface and contract address one more.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 24 at 12:22
0

This error usually occurs when the interface you are using is not correctly picking up the functions from the contract address you are passing in it.

Wherever you are doing the following in smart contract,

InterfaceExample(contractAddress).function();

Please check if the function arguments, return values and the name are in sync at three places.

  1. Base contract.
  2. Interface.
  3. Contract where you are callling that particular function.
-2

If you are using hardhat make sure you import to metamask the accounts displayed when you enter the npx hardhat accounts command. Don't use outside accounts.

Not the answer you're looking for? Browse other questions tagged or ask your own question.