Skip to main content
Version: 2.0

Querying a transaction

Gets the current state of a previously sent asynchronous transaction request.

await API.poll.requestState(requestId);
important

To query a transaction, you would need the request id returned after submitting your transaction to the AVN.

You can get the AVN_GATEWAY_URL here.

Result Fields

  • txHash - string representing the transaction hash.
  • status - string detailing the current status.
  • blockNumber [if status is 'Processed' or 'Rejected'] - string integer representing the block number containing this transaction.
  • transactionIndex [if status is 'Processed' or 'Rejected'] - string integer representing the (zero-based) index of this transaction in the block.

Possible STATUS Outcomes

The resulting state could be any of the following:

  • Pending
  • Rejected
  • Processed
  • Transaction not found
const AVN_API = require("avn-api");
const AVN_GATEWAY_URL = "<node_url>";
const options = {
suri: "<account_suri>",
};
const API = new AVN_API(AVN_GATEWAY_URL, options);

async function main() {
await API.init();
}

async function confirmTransaction(api, requestId) {
for (i = 0; i < 10; i++) {
await sleep(6000);
// Poll transaction status by request ID:
const polledState = await api.poll.requestState(requestId);
if (polledState.status === "Processed") {
console.log("Transaction processed");
break;
} else if (polledState.status === "Rejected") {
console.log("Transaction failed");
break;
}
}
}
async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

(async () => {
await main();
await confirmTransaction(API, <requestId>)
})();