useWeb3ExecuteFunction() causes metamask RPC error

Hi, I am trying to execute a function which initialises candidates in an election. Solidity code has been tested on Remix and all functions work as expected. Was able to read data from the contract deployed on Ganache just not execute write functions.

When using useWeb3ExecuteFunction() and passing params on a write contract I get this error
MetaMask - RPC Error: Internal JSON-RPC error

Below are the snippets of code executing the function

const { data, error, fetch, isFetching, isLoading } = useWeb3ExecuteFunction({
    abi: ABI.abi,
    contractAddress: "0xCC23f2d4296c4e94d544e6ee2398DA25Bcdccc0f",
    functionName: "createElection",
    params: {
      _name: ["John", "Mary"],
    },
  });
<Button
          onClick={() => fetch({ params: options })}
          disabled={isFetching}
        >
          Fetch data
        </Button>

what kind of parameter is this?

how does the abi looks like?

That is for an array of strings

function createElection(string[] memory _name) public {

The Abi is extracted straight from my json so there should be no issues with it

"abi": [
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "cand1Count",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [],
      "name": "cand2Count",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [],
      "name": "candidatesCount",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [],
      "name": "electionCount",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "name": "elections",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "elecID",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [],
      "name": "voteID",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [
        {
          "internalType": "string[]",
          "name": "_name",
          "type": "string[]"
        }
      ],
      "name": "createElection",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "_elecID",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "_candID",
          "type": "uint256"
        }
      ],
      "name": "getCandidate",
      "outputs": [
        {
          "internalType": "string",
          "name": "",
          "type": "string"
        },
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "_elecID",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "_candID",
          "type": "uint256"
        }
      ],
      "name": "createVote",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "_elecID",
          "type": "uint256"
        },
        {
          "internalType": "uint256",
          "name": "_voteID",
          "type": "uint256"
        }
      ],
      "name": "hasVoted",
      "outputs": [
        {
          "internalType": "bool",
          "name": "",
          "type": "bool"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    }
  ]

Not sure what I fixed, but was testing my contract and made changes. When you replied I reverted them back so to send code snippets and now its working :slight_smile: .

However now after hitting confirm on the transaction my page crashes with this error. More react related but maybe you have an idea.

Uncaught Error: Objects are not valid as a React child

I don’t have an idea on this error

No worries thanks for getting back to me, it unintentionally fixed my issue :slight_smile: