You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm encountering an issue with writeContractAsync. After calling this function, I'm not always receiving the transaction hash, and it seems like the transaction gets stuck indefinitely, even though I have already signed it.
Here is my code:
const handleWrite = async () => {
console.log('WRITE!');
onSubmit();
let transactionHash = null;
let notificationId = null;
try {
// Prepare the transaction parameters
const params = {
chainId,
address: contractAddress,
functionName: abiFunction.name,
abi: [abiFunction],
args: getParsedContractFunctionArgs(form),
};
console.log('Sending transaction with parameters:', params);
notificationId = notification.loading(
<TxnNotification message="Awaiting for user confirmation" />
);
// Send the transaction
transactionHash = await writeContractAsync(params); // Stucks awaiting for transaction here and never ends
if (onProgress) {
onProgress(transactionHash, params);
}
notification.remove(notificationId);
console.log('Transaction sent, hash:', transactionHash);
// Wait for transaction receipt
const blockExplorerTxURL = chainId
? getBlockExplorerTxLink(chainId, transactionHash)
: '';
notificationId = notification.loading(
<TxnNotification
message="Waiting for transaction to complete."
blockExplorerLink={blockExplorerTxURL}
/>
);
// Wait for the transaction confirmation
const transactionReceipt = await waitForTransactionReceipt(wagmiConfig, {
hash: transactionHash,
confirmations: 2, // Number of required confirmations
timeout: 120000, // Timeout in milliseconds (120 seconds)
});
notification.remove(notificationId);
console.log('Transaction receipt:', transactionReceipt);
// Check if the transaction was successful
if (transactionReceipt.status === 'success') {
onSuccess({
chainId,
address: contractAddress,
functionName: abiFunction.name,
abi: [abiFunction],
args: getParsedContractFunctionArgs(form),
hash: transactionHash,
receipt: transactionReceipt,
});
notification.success(
<TxnNotification
message="Transaction completed successfully!"
blockExplorerLink={blockExplorerTxURL}
/>,
{
icon: '🎉',
}
);
}
} catch (e) {
const message = getParsedError(e);
notification.remove(notificationId);
notification.error(<TxnNotification message={message} />);
}
};
Issue Details:
As mentioned, sometimes I receive the transaction hash after confirming, but most of the time, the transaction seems to be stuck indefinitely, even though the transaction is confirmed on the blockchain.
NOTE: I'm using a free plan RPC from Infura, and my project dependencies are as follows:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm encountering an issue with writeContractAsync. After calling this function, I'm not always receiving the transaction hash, and it seems like the transaction gets stuck indefinitely, even though I have already signed it.
Here is my code:
Issue Details:
As mentioned, sometimes I receive the transaction hash after confirming, but most of the time, the transaction seems to be stuck indefinitely, even though the transaction is confirmed on the blockchain.
NOTE: I'm using a free plan RPC from Infura, and my project dependencies are as follows:
Beta Was this translation helpful? Give feedback.
All reactions