Documentation Index Fetch the complete documentation index at: https://docs.ondb.ai/llms.txt
Use this file to discover all available pages before exploring further.
Monitor transaction status in real-time using the SDK’s event system.
Event Types
Event Description transaction:queuedTask queued with ticket transaction:pendingTransaction pending transaction:confirmedTransaction confirmed transaction:failedTransaction failed errorGeneral error occurred
Setting Up Event Listeners (TypeScript)
The TypeScript SDK provides a rich event system for transaction tracking:
import { createClient } from '@ondb/sdk' ;
const client = createClient ({
endpoint: 'https://api.ondb.io' ,
appKey: 'your-app-key'
});
// Listen for transaction events
client . on ( 'transaction:queued' , ( ticket ) => {
console . log ( `Task ${ ticket . ticket_id } queued: ${ ticket . message } ` );
});
client . on ( 'transaction:pending' , ( tx ) => {
console . log ( `Transaction ${ tx . id } is pending...` );
});
client . on ( 'transaction:confirmed' , ( tx ) => {
console . log ( `Transaction ${ tx . id } confirmed at block ${ tx . block_height } ` );
});
client . on ( 'transaction:failed' , ( tx ) => {
console . error ( `Transaction ${ tx . id } failed: ${ tx . error } ` );
});
client . on ( 'error' , ( error ) => {
console . error ( 'Error occurred:' , error );
});
// Store data - events will be emitted automatically
await client . store (
{ collection: 'messages' , data: [{ message: 'Hello' }] },
paymentCallback
);
Polling-Based Tracking (All SDKs)
For SDKs without event support, use polling:
async function trackTransaction ( ticketId : string ) {
const maxAttempts = 60 ;
const pollInterval = 2000 ;
for ( let i = 0 ; i < maxAttempts ; i ++ ) {
const status = await client . getTaskStatus ( ticketId );
console . log ( `Status: ${ status . status } ` );
if ( status . status === 'Completed' ) {
return { success: true , data: status };
}
if ( status . status === 'Failed' ) {
return { success: false , error: status . error };
}
await new Promise ( r => setTimeout ( r , pollInterval ));
}
throw new Error ( 'Transaction tracking timeout' );
}
Transaction State Machine
UI Integration Example
// Track all transactions in a Map
const transactions = new Map ();
client . on ( 'transaction:queued' , ( ticket ) => {
transactions . set ( ticket . ticket_id , {
id: ticket . ticket_id ,
status: 'queued' ,
message: ticket . message ,
timestamp: new Date ()
});
updateUI ();
});
client . on ( 'transaction:confirmed' , ( tx ) => {
const existing = transactions . get ( tx . id );
if ( existing ) {
existing . status = 'confirmed' ;
existing . block_height = tx . block_height ;
existing . transaction_hash = tx . transaction_hash ;
updateUI ();
}
});
client . on ( 'transaction:failed' , ( tx ) => {
const existing = transactions . get ( tx . id );
if ( existing ) {
existing . status = 'failed' ;
existing . error = tx . error ;
updateUI ();
}
});
function updateUI () {
const list = document . getElementById ( 'transactions' );
list . innerHTML = '' ;
transactions . forEach (( tx , id ) => {
const item = document . createElement ( 'div' );
item . className = `transaction ${ tx . status } ` ;
item . innerHTML = `
<span class="id"> ${ id } </span>
<span class="status"> ${ tx . status } </span>
${ tx . block_height ? `<span>Block: ${ tx . block_height } </span>` : '' }
${ tx . error ? `<span class="error"> ${ tx . error } </span>` : '' }
` ;
list . appendChild ( item );
});
}
Removing Listeners (TypeScript)
// Remove specific listener
const handler = ( tx ) => console . log ( tx );
client . on ( 'transaction:confirmed' , handler );
client . off ( 'transaction:confirmed' , handler );
// Remove all listeners for an event
client . removeAllListeners ( 'transaction:confirmed' );
Next Steps
Error Handling Handle errors gracefully
Task Management Async operation tracking