I have a hook that I want to call in handleSubmit. The data from this hook will be passed to another hook, and based on the response from the second hook, I want to push different pages.
The first hook:
const write = useContractWrite(
{
addressOrName: Address,
contractInterface: Interface,
},
'entry',
{
args: [firstAnswer.trim().toLowerCase(), secondAnswer.trim().toLowerCase()],
overrides: {
value: ethers.utils.parseEther("0.01")
}
}
)
Documentation for useContractWrite
I have another hook that relies on the data of the useContractWrite hook:
const waitForTransaction = useWaitForTransaction({
wait: write!.data?.wait,
onSettled(data, error) {
console.log("Settled", { data })
}
});
Docs for useWaitForTransaction
And finally, my handleSubmit:
async function handleSubmit() {
if (firstAnswer.length == 0 || secondAnswer.length == 0) {
setInputError(true);
}
else {
setInputError(false);
//write
const txn = write;
// console.log(write + "writeData")
//wait
// console.log(waitForTransaction.data + "waitData")
}
}
Unfortunately, the
writefunction is not being called in handleSubmit. So, I make it callableChanging the write to the following:
const { write } = useContractWritemakes it callableconst txn = write();But, I am unable to pass the
txn!.data.waitto useWaitForTransaction like so:const txn = write(); //wait waitForTransaction({wait: txn!.data?.wait});```The error I get when attempting to pass
txn.data.waittowaitForTransactionis that the waitForTransaction is not callableThis expression is not callable.So, I make it callable:
const { waitForTransaction } = useWaitForTransaction({...})Now, I get the following error on the useWaitForTransaction Hook:
Property 'waitForTransaction' does not exist on type 'Pick<QueryObserverResult<TransactionReceipt, Error>, "data" | "error" | "isError" | "isLoading" | "isSuccess" | "isFetched" | "isFetching" | "isRefetching" | "refetch" | "fetchStatus"> & { ...; }'
I am sure there is an easy fix to this, but I do not see where the issue lies. I have followed the docs to a tee and it is not working.