有人可以帮助跟踪 MultiversX 网络上价值转移的交易状态吗?
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'
}
});
我目前正在使用
sendTransactions
发送我的交易。
根据erdjs文档的说明,可以使用TransactionWatcher。
下面是文档中的简化示例:
await tx1.send(provider);
let watcher = new TransactionWatcher(tx1.hash, provider);
await watcher.awaitStatus(status => status.isExecuted());
erdjs 文档:https://elrondnetwork.github.io/elrond-sdk-docs/erdjs/latest/
我没能使用观察者,所以我每 0.5 秒从 sessionStorage 读取一次数据,直到状态为“成功”
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);
}
}