[SOLVED][React moralis] `useWeb3Contract` does not work with params

Hello! Iā€™m facing some issues running my chainlink performUpkeep function on FE that take in parameters. Iā€™ve also tried with other setter functions on my contract, but nothing happens as well. Iā€™ve seen people write similar code online for setter functions and it seemed to work for them, so Iā€™m really at my wits end here.

For additional context, the below code works for getter functions where params are empty, aka params: {}

const { runContractFunction: performUpkeep } = useWeb3Contract({
        abi: abi,
        contractAddress: raffleAddress,
        functionName: "performUpkeep",
        params: { performData: 0x0 }, // I suspect something is wrong with this, but I'm not sure
    })
// The function in the contract
function performUpkeep(bytes calldata /* performData */) external override {}

So I try to run performUpkeep in my FE via a button, but nothing happens. Also, the parameter here is actually unused in my contract. Which is why itā€™s commented out

Iā€™m unsure how to debug this or move forward. Would appreciate some help! Thank you!!

Can you also post your code how you call performUpkeep (with the button). Make sure that your wallet is on the right chain for this contract.

Try logging error from useWeb3Contract in a useEffect to see if there is one.

useEffect(() => {
  console.log("err", error);
}, [error]);
1 Like

hmm, thanks for the reply!
It seems iā€™m getting the error below ā€œundefined is requiredā€. Hmm, Iā€™ve checked that performUpkeep is of type function, but how else do I debug from here? I did a quick google search and couldnā€™t find anyone with similar error as this.

image

Additional context of my code:

const handleSelectWinnerSuccess = async (tx) => {
        await tx.wait(1)
        dispatch({
            type: "success",
            message: "Winner Selected!",
            title: "Winner Selected",
            position: "topR",
        })
    }

const selectWinnerBtn = async () => {
        await performUpkeep({
            onSuccess: handleSelectWinnerSuccess,
            onError: (err) => console.log(err),
        })
    }

What is your contract ABI (or address if the code is verified)? Looks like an issue with the ABI.

1 Like
  {
    "type": "function",
    "name": "performUpkeep",
    "constant": false,
    "payable": false,
    "gas": 2000000,
    "inputs": [
      {
        "type": "bytes"
      }
    ],
    "outputs": []
  },

This is the specific part for this function.

The rest is here
[{"type":"constructor","payable":false,"inputs":[{"type":"address","name":"vrfCoordinatorV2"},{"type":"uint64","name":"subId"},{"type":"bytes32","name":"keyHash"},{"type":"uint256","name":"interval"},{"type":"uint32","name":"cbGasLimit"}]},{"type":"error","name":"ErrorPayingWinner","inputs":[]},{"type":"error","name":"OnlyCoordinatorCanFulfill","inputs":[{"type":"address","name":"have"},{"type":"address","name":"want"}]},{"type":"error","name":"RaffleHasNoBidders","inputs":[]},{"type":"error","name":"RaffleInsuficientFunds","inputs":[{"type":"uint256","name":"msgValue"},{"type":"uint256","name":"requiredValue"}]},{"type":"error","name":"RaffleNotOpen","inputs":[]},{"type":"error","name":"RaffleUpkeepNotNeeded","inputs":[{"type":"uint256","name":"currentBalance"},{"type":"uint256","name":"numPlayers"},{"type":"uint256","name":"raffleState"}]},{"type":"error","name":"Unauthorized","inputs":[]},{"type":"event","anonymous":false,"name":"RaffleEnter","inputs":[{"type":"address","name":"player","indexed":true}]},{"type":"event","anonymous":false,"name":"RequestedRaffleWinner","inputs":[{"type":"uint256","name":"requestId","indexed":true}]},{"type":"event","anonymous":false,"name":"WinnerPicked","inputs":[{"type":"address","name":"player","indexed":true}]},{"type":"function","name":"addAdmin","constant":false,"payable":false,"gas":2000000,"inputs":[{"type":"address","name":"_newAdmin"}],"outputs":[]},{"type":"function","name":"buyTickets","constant":false,"stateMutability":"payable","payable":true,"gas":2000000,"inputs":[],"outputs":[]},{"type":"function","name":"changeTicketCost","constant":false,"payable":false,"gas":2000000,"inputs":[{"type":"uint256","name":"newTixCost"}],"outputs":[]},{"type":"function","name":"checkUpkeep","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[{"type":"bytes"}],"outputs":[{"type":"bool","name":"upkeepNeeded"},{"type":"bytes"}]},{"type":"function","name":"getContestant","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[{"type":"uint256","name":"index"}],"outputs":[{"type":"address"}]},{"type":"function","name":"getInterval","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getLastTimeStamp","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getNumContestants","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getNumTickets","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getNumWords","constant":true,"stateMutability":"pure","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getRaffleState","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint8"}]},{"type":"function","name":"getRecentWinner","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"address"}]},{"type":"function","name":"getRequestConfirmations","constant":true,"stateMutability":"pure","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getTicketCost","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"getUserTickets","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"uint256"}]},{"type":"function","name":"isUserAdmin","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[],"outputs":[{"type":"bool"}]},{"type":"function","name":"performUpkeep","constant":false,"payable":false,"gas":2000000,"inputs":[{"type":"bytes"}],"outputs":[]},{"type":"function","name":"rawFulfillRandomWords","constant":false,"payable":false,"gas":2000000,"inputs":[{"type":"uint256","name":"requestId"},{"type":"uint256[]","name":"randomWords"}],"outputs":[]},{"type":"function","name":"tickets","constant":true,"stateMutability":"view","payable":false,"gas":2000000,"inputs":[{"type":"address"}],"outputs":[{"type":"uint256"}]}]

Could it be the ā€œstate mutabilityā€ field thatā€™s missing?

Thank you very much!!

ā€œinputsā€: [
{
ā€œtypeā€: ā€œbytesā€
}
],

This is the generated ABI from this contract? What is your full contract code? Usually there is a name for an input as well. Maybe try editing it manually to match your params:

{ internalType: 'bytes', name: 'performData', type: 'bytes' },

// or 

{ name: 'performData', type: 'bytes' },

...

stateMutability: 'nonpayable',

Where did you get performData from?

1 Like

Because this is an over-ridden function from chainlink keepers/automation. The parameter actually isnā€™t used in my function.

i was putting performData just to test to see if it works, but maybe itā€™s not needed O.o

Any param names used would need to be in the ABI. Maybe you need to call this function differently - you can check Chainlink docs.

1 Like


Thank you very much!!! It works now ^^

Not sure if this is the same solution that the OP found as it appears to say it was solved, but no solution appears to be posted. but I solved the problem like this:

const { runContractFunction: checkUpkeep } = useWeb3Contract ({
abi: abi,
contractAddress: raffleAddress,
functionName: ā€œcheckUpkeepā€,
params: {performData: ā€œ0x00ā€ },
})