2

Can someone help with tracking the transaction status of a value transfer on the elrond network?

   const testTransaction = new Transaction({
      value: Balance.egld(1),
      data: new TransactionPayload('Test Transfer'),
      receiver: new Address(ownerWallet),
      nonce: sender.nonce,
      gasPrice: new GasPrice(10000000000,
      gasLimit: new GasLimit(1000000)
    });

    await refreshAccount();

    const { sessionId  } = await sendTransactions({
      transactions: testTransaction,
      transactionsDisplayInfo: {
        processingMessage: 'Processing transaction',
        errorMessage: 'An error has occured during Transaction',
        successMessage: 'Transaction successful'
      }
    });

I am currently using sendTransactions to send my transaction.

5ymmetric
  • 31
  • 2

2 Answers2

2

According to the documentation of the erdjs documentation, you can use the TransactionWatcher.

Here's below a reduced example from the documentation:

await tx1.send(provider);

let watcher = new TransactionWatcher(tx1.hash, provider);
await watcher.awaitStatus(status => status.isExecuted());

The erdjs doc: https://elrondnetwork.github.io/elrond-sdk-docs/erdjs/latest/

Fargerik
  • 210
  • 2
  • 6
0

I didn't manage to use the watcher so I read the data from sessionStorage every 0.5 seconds until status is 'success'

let transactions = JSON.parse(sessionStorage.getItem('persist:dapp-core-transactions'));
    const txData = JSON.parse(sessionStorage.getItem('txData'));
    let txSessionId = sessionStorage.getItem('txSessionId');
    let signedTransactions = JSON.parse(transactions.signedTransactions);
    let currentTransaction = signedTransactions[txSessionId];
    // if (currentTransaction != null) {
    //     let transactionOnNetwork = await watcher.awaitCompleted();
    //     console.log(transactionOnNetwork);
    // }

    // console.log(signedTransactions);
    if (currentTransaction && txSessionId) {
        console.log(currentTransaction);
        if (currentTransaction.status === 'sent') {
            const checkTransaction = setInterval(async () => {
                console.log("Checking transaction status");
                let transactions = JSON.parse(sessionStorage.getItem('persist:dapp-core-transactions'));
                let signedTransactions = JSON.parse(transactions.signedTransactions);
                let currentTransaction = signedTransactions[txSessionId];
                if (currentTransaction.status === 'success' && txData) {
                    clearInterval(checkTransaction);                        
                    await doSomething(currentTransaction);
                    sessionStorage.removeItem('txSessionId');
                }
            }, 500);
        }
    }