Skip to content

Instantly share code, notes, and snippets.

@AndreVallestero
Last active November 15, 2021 16:45
Show Gist options
  • Select an option

  • Save AndreVallestero/b50cbf72598bfc5103bb529f5be5e1e6 to your computer and use it in GitHub Desktop.

Select an option

Save AndreVallestero/b50cbf72598bfc5103bb529f5be5e1e6 to your computer and use it in GitHub Desktop.
// timeout in ms
async function checkTxConfirmation(txId, timeout) {
console.log(`Waiting for TX: ${txId}`);
const start = Date.now();
for (;;) {
const status = (await arweave.transactions.getStatus(txId)).status;
switch (status) {
case 202:
case 404:
break;
case 200:
console.log("Transaction found");
return true;
default:
console.error(`Status ${status} while checking tx confirmation`);
return false;
}
const elapsed = Date.now() - start;
if (timeout && elapsed > timeout) return false
console.log(Math.round(elapsed / 60000) + "m waiting");
await new Promise((resolve) => setTimeout(resolve, 60000));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment