pollTransactionStatus
Continuously monitors a transaction's status by polling at regular intervals until a final state is reached or timeout occurs. This method provides a convenient way to track cross-chain transactions through their entire lifecycle.
interface PollTransactionStatusParams {
// Route ID of the transaction
routeId: string;
// Step ID being monitored
stepId: string;
// Transaction hash from the blockchain
txnHash: string;
// Optional: Interval between status checks in milliseconds (default: 2000ms)
pollingIntervalMs?: number;
// Optional: Maximum time to poll before timing out in milliseconds (default: 600000ms / 10 minutes)
timeoutMs?: number;
// Optional: Callback function for real-time status updates
onStatusUpdate?: (status: TransactionStatus, data?: ExecuteTransactionResult) => void;
}
// Example usage:
const result = await pollTransactionStatus({
routeId: "your-route-id",
stepId: "your-step-id",
txnHash: "your-transaction-hash",
pollingIntervalMs: 3000, // Poll every 3 seconds, by default it's 2 seconds
timeoutMs: 300000, // Timeout after 5 minutes, by default it's 10 minutes
onStatusUpdate: (status, data) => {
console.log(`Transaction status updated: ${status}`);
if (data) {
console.log("Transaction data:", data);
}
},
});
// Example Response
{
"status": "success",
"data": {
"status": "success",
"outputAmount": "1459244847",
"outputAmountDisplay": "1459.244847",
"srcTxnHash": "0x...",
"dstTxnHash": "0x...",
"srcTxnUrl": "https://etherscan.io/tx/0x...",
"dstTxnUrl": "https://etherscan.io/tx/0x...",
"points": 100,
"warnings": [],
}
}
The method will continue polling until one of these conditions is met:
Transaction reaches a final status ("success", "failed", or "partial-success")
Polling timeout is reached
An error occurs during status checking
Status Types:
"not-started"
: Transaction has not been initiated"in-progress"
: Transaction is being processed"success"
: Transaction completed successfully"failed"
: Transaction failed"partial-success"
: Transaction partially succeeded (some steps completed)
Error Handling:
Throws a timeout error if
timeoutMs
is exceededThrows any errors encountered during status checking
Provides detailed error information through the
BlockendError
class
Best Practices:
Set appropriate
pollingIntervalMs
based on chain block timesConfigure reasonable
timeoutMs
for your use caseImplement proper error handling
Use the
onStatusUpdate
callback for real-time UI updates
Last updated
Was this helpful?