Skip to main content
Version: 0.6

Querying a transaction

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

info

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

await API.poll.requestState(requestId);

Example

const AVN_API = require("avn-api");
//Replace the endpoint_url with the url received from Aventus.
const AVN_GATEWAY_URL = "<endpoint_url>";
const API = new AVN_API(AVN_GATEWAY_URL);

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

async function confirmTransaction(api, requestId) {
for (i = 0; i < 10; i++) {
await sleep(3000);
// 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>)
})();

Example Result

{
"txHash": "0x37b5aa64e1b56c2d250588ffe0c73d810783ef8ec60eaae1c773c0acbc63dc90",
"status": "Processed",
"blockNumber": "125412",
"transactionIndex": "2"
}

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

JSON-RPC

REQUEST
POST https://AVN-API-URL/poll

HEADERS
Content-Type: application/json Authorization': bearer <awtToken>

REQUEST PARAMS

  • requestId [required] - string representing the request ID.

JSON-RPC Example

curl https://AVN-API-URL/poll \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"requestState", "params":{"requestId":"410fe1c5-5deb-4a52-b89d-8bc9fc682415"}, "id":1}'

Example Output

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"txHash": "0x37b5aa64e1b56c2d250588ffe0c73d810783ef8ec60eaae1c773c0acbc63dc90",
"status": "Processed",
"blockNumber": "125412",
"transactionIndex": "2"
}
}