-
Notifications
You must be signed in to change notification settings - Fork 3
Check Transaction Status
Chain of Industry edited this page Dec 1, 2022
·
5 revisions
After a transaction is submitted to the blockchain (see Send EGLD Transaction), it takes some time for a validator to process it. An app needs to check if that transaction was successfully processed or not before continuing execution. This section shows how to check the status of a submitted transaction.
To check the status of a transaction this API method will be used:
/// <summary>
/// Check the status of a specific transaction
/// </summary>
/// <param name="txHash">The hash of the transaction obtained after signing</param>
/// <param name="transactionProcessed">Callback to track the result</param>
/// <param name="delay">Time to wait before querying the tx status. A tx takes some time to process so some delays are good to limit the usage of APIs</param>
public static void CheckTransactionStatus(string txHash, UnityAction<OperationStatus, string> transactionProcessed, float delay)
A usage example:
//after a transaction is successfully signed, this callback is triggered[see Send EGLD Transaction example]
private void SigningStatusListener(MultiversXUnityTools.OperationStatus operationStatus, string message)
{
if (operationStatus == MultiversXUnityTools.OperationStatus.Complete)
{
txHash = message;
//txHash - transaction hash
//BlockchainTransactionListener - callback
//6 - time to wait before checking the transaction status(6s is the MultiversX block time, it takes at least a block to process a transaction)
MultiversXUnityTools.Manager.CheckTransactionStatus(txHash, TransactionProcessed, 6);
}
}
/// <summary>
/// Listener for the transaction status response
/// </summary>
/// <param name="operationStatus">Completed, In progress or Error</param>
/// <param name="message">additional message</param>
private void TransactionProcessed(MultiversXUnityTools.OperationStatus operationStatus, string message)
{
if (operationStatus == OperationStatus.Complete)
{
//after a transaction is processed, refresh account balance
MultiversXUnityTools.Manager.RefreshAccount(RefreshDone);
}
else
{
//process failed transactions
}
}
This concludes the Check Transaction Status Unity tutorial.
Recommended next: Send ESDT Transaction