Cannot get tx hash from signTransactions or sendTransactions
I need to watch tx and send tx hash to the backend to let the backend monitor tx. Is there a way to get the hash of a tx?
Hi! after sending transactions you get a sessionId. You can use that to track your transaction like this:
const { successfulTransactions } = useGetSuccessfulTransactions();
const isSessionIdSuccessful = sessionId in successfulTransactions;
this is how you would get the hash:
const { successfulTransactions } = useGetSuccessfulTransactions();
const sessionInfo = successfulTransactions[sessionId];
sessionInfo?.transactions?.[0].hash
Or you can use the built-in hook:
const { pending, success, fail, timedOut } = useGetActiveTransactionsStatus();
You can find these methods in the documentation
Hope this helps
Thank you.
Can you make signTransaction and sendTransaction return tx hash in SendTransactionReturnType?
Tx Hash is essential for many cases, such as TxWatcher.
Your method is complicated to just get a hash - using TxWatcher is difficult.
By the way, I can't find sessionInfo?.transactions?.[0].hash in the documentation.
Thank you again.
I need to get tx hash when the tx is signed & sent.
useGetSuccessfulTransactions(); function only returns successful tx but I need all tx whethere it succeeded or failed.
const { sessionId } = await sendTransactions({ transactions: [tx]});
const transactionStatus = useTrackTransactionStatus({
transactionId: sessionId,
onSuccess: () => {console.log('success');},
onFail: () => {console.log('fail');},
onCancelled: () => {console.log('cancelled');},
});
I need to sent the tx hash just after User sends it but I can't find a way to do it now. If you returns tx hash instead of sessionId (I don't understand why you introduced extra hash value), the problem can be resolved.
What you can do is get the transactions from dapp-core by providing signWithoutSending flag true. Then get the signed transaction and send it yourself, and get the response hash. Please let me know if this is helpful so I can close the issue
I already got tx hash with hasPendingTransactions hook. However, I need to make extras steps and store & clear sessiondId to get a tx hash. It's inconvenient. With hardhat or other EVM js libraries, I can get tx hash without an extra step.
I will close the issue because a workaround was found. Many improvements will come in the next releases.