Skip to main content
Version: 3.5.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.
  • senderNonce : string representing the nonce of the sender account.
  • eventArgs : an object containing values returned as a result of the transaction.

Possible STATUS Outcomes

The resulting state could be any of the following:

  • Pending - Transaction has been sent via the Gateway and is yet to be fully processed.
  • Rejected - The transaction has been rejected by the blockchain.
  • Processed - The transaction has been processed successfully by the blockchain.
  • Transaction not found - The transaction relating to the supplied request-id cannot be found.
  • awaitingToSend - The transaction has yet to be sent to the blockchain.
  • Validating - This state is restricted to cross-chain transactions.
const { AvnApi, SetupMode, SigningMode } = require("avn-api");
const AVN_GATEWAY_URL = "gateway url of your chosen network"
const options = {
suri: "suri of your account",
setupMode: SetupMode.SingleUser,
signingMode: SigningMode.SuriBased,
hasPayer: true,
};

async function main(requestId) {
const avnSdk = new AvnApi(AVN_GATEWAY_URL, options);
await avnSdk.init();
const api = await avnSdk.apis();

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>)
})();