Hello guys,
I have a problem interacting with my contract in reactjs. The thing is if I set up my funcitons in a InteractWithContract.js file and add it to my mint page as <InteractWithContract/>
it works just fine.
if I add the function in my mint page there is no reaction when calling the runContractFunction. The onSuccess, onComplete, onError of the runContractFunction are firing immediately. I already spent multiple hours now, just cant get it working.
here is my code (contractAddress I have changed to myContract for placing it here)
//interact start
const { runContractFunction: enterRaffle, data: enterTxResponse, error, isLoading, isFetching } = useWeb3Contract({
abi: abi,
contractAddress: "myContract",
functionName: "addAddress",
params: {
_addressToBeAdded: account
},
}
);
const InteractContract = async () => {
console.log("abi", abi);
console.log("web3en", isWeb3Enabled)
console.log("raffleresult", await enterRaffle(
{
onSuccess: console.log("success"),
onComplete: console.log("complete"),
//onError: () => { handleError(JSON.stringify(error)) },
onError: console.log("error")
}
))
await enterRaffle(
{
onSuccess: console.log("success"),
onComplete: console.log("complete"),
//onError: () => { handleError(JSON.stringify(error)) },
onError: console.log("error")
}
)
}
and for activating it:
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded ml-auto"
onClick={async () =>
await InteractContract()
}
disabled={isLoading || isFetching}
>enter raffle</button>