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 tocross-chain
transactions.
- Example
- Example Result
- JSON-RPC
- JSON-RPC Output
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,
};
const avnSdk = new AvnApi(AVN_GATEWAY_URL, options);
await avnSdk.init();
async function main(requestId) {
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>)
})();
{
"txHash": "0x37b5aa64e1b56c2d250588ffe0c73d810783ef8ec60eaae1c773c0acbc63dc90",
"status": "Processed",
"blockNumber": "125412",
"transactionIndex": "2"
}
REQUEST
POST https://AVN_GATEWAY_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_GATEWAY_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}'
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"txHash": "0x37b5aa64e1b56c2d250588ffe0c73d810783ef8ec60eaae1c773c0acbc63dc90",
"status": "Processed",
"blockNumber": "125412",
"transactionIndex": "2"
}
}