- OperationTracker Class
OperationTracker allows monitoring the lifecycle of cross-chain transactions between TON and TAC.
It queries multiple Lite Sequencer endpoints for status updates, execution breakdowns, and operation IDs associated with TON transactions, providing automatic failover if one endpoint fails.
After calling TacSdk.sendCrossChainTransaction(...), a TransactionLinker object is returned.
This linker allows tracking status of the operation through these steps:
- Use
getOperationId(linker)to fetch the cross-chain operation ID. - Use
getOperationStatus(...)orgetSimplifiedOperationStatus(...)to get the current state. - For debugging or performance profiling, use
getStageProfiling(...).
For automated polling, use
startTracking()which handles all the above and prints status updates.
new OperationTracker(
network: Network,
customLiteSequencerEndpoints?: string[],
logger?: ILogger,
clientFactory?: ILiteSequencerClientFactory
)Creates a new OperationTracker instance.
Parameters:
network: Network type (TESTNET or MAINNET)customLiteSequencerEndpoints(optional): Custom sequencer endpoints. If not provided, uses default endpoints for the networklogger(optional): Logger implementation (defaults toNoopLogger)clientFactory(optional): Factory for creating sequencer clients (defaults toDefaultLiteSequencerClientFactory)
import { OperationTracker, Network } from "@tonappchain/sdk";
import { ConsoleLogger } from "@tonappchain/sdk";
// Basic usage with defaults
const tracker = new OperationTracker(Network.TESTNET);
// With custom endpoints and logging
const trackerWithOptions = new OperationTracker(
Network.TESTNET,
["https://your-sequencer.com"], // customLiteSequencerEndpoints
new ConsoleLogger(), // logger
// clientFactory (optional)
);OperationTracker implements the IOperationTracker interface and uses multiple ILiteSequencerClient instances internally to provide high availability and automatic failover.
Factory interface for creating sequencer clients. The default implementation (DefaultLiteSequencerClientFactory) creates LiteSequencerClient instances.
Interface that defines the operations supported by sequencer clients:
getOperationType(operationId: string): Promise<OperationType>getOperationId(transactionLinker: TransactionLinker): Promise<string>getOperationIdByTransactionHash(transactionHash: string): Promise<string>getOperationIdsByShardsKeys(shardsKeys: string[], caller: string, chunkSize?: number): Promise<OperationIdsByShardsKey>getStageProfilings(operationIds: string[], chunkSize?: number): Promise<ExecutionStagesByOperationId>getOperationStatuses(operationIds: string[], chunkSize?: number): Promise<StatusInfosByOperationId>
- Each endpoint is wrapped in its own
ILiteSequencerClientimplementation - Requests are tried on each client in sequence until one succeeds
- If all clients fail, an
AllEndpointsFailedErroris thrown
This architecture provides:
- High Availability: Automatic failover if an endpoint is down
- Load Distribution: Requests spread across multiple endpoints
- Testability: Interface-based design allows for easy mocking and testing
- Consistent Interface: Same API regardless of endpoint availability
For more details about the underlying client, see LiteSequencerClient.
All methods in OperationTracker support an optional waitOptions parameter that enables automatic retrying and waiting for successful results:
interface WaitOptions<T = unknown, TContext = unknown> {
/**
* Timeout in milliseconds
* @default 300000 (5 minutes)
*/
timeout?: number;
/**
* Maximum number of attempts
* @default 30
*/
maxAttempts?: number;
/**
* Delay between attempts in milliseconds
* @default 10000 (10 seconds)
*/
delay?: number;
/**
* Logger
*/
logger?: ILogger;
/**
* Optional context object to pass additional parameters to callbacks
* This allows passing custom data like OperationTracker instances, configurations, etc.
*/
context?: TContext;
/**
* Function to check if the result is successful
* If not provided, any non-error result is considered successful
*/
successCheck?: (result: T, context?: TContext) => boolean;
/**
* Custom callback function that executes when operation is successful
* Receives both the result and optional context with additional parameters
* Can be used for additional processing like profiling data retrieval
*/
onSuccess?: (result: T, context?: TContext) => Promise<void> | void;
/**
* Include underlying stack trace in FetchError.innerStack when all endpoints fail
* @default false
*/
includeErrorTrace?: boolean;
}When waitOptions is not specified (undefined):
All OperationTracker methods automatically use default retry settings:
timeout: 300000ms (5 minutes) - fromDEFAULT_WAIT_TIMEOUT_MSmaxAttempts: 30 - fromDEFAULT_WAIT_MAX_ATTEMPTSdelay: 10000ms (10 seconds) - fromDEFAULT_WAIT_DELAY_MS- Logger from the
OperationTrackerinstance is automatically passed
This ensures resilient behavior against rate limits and temporary network issues.
To disable retry behavior and use a single attempt, explicitly pass null:
// Single attempt, no retries
await tracker.getOperationId(linker, null);To customize retry behavior, pass a WaitOptions object:
// Custom retry settings
await tracker.getOperationId(linker, {
maxAttempts: 5,
delay: 2000,
timeout: 60000
});For comprehensive examples and usage patterns, including detailed context parameter usage, see the Enhanced WaitOptions Examples documentation.
getOperationId(
transactionLinker: TransactionLinker,
waitOptions?: WaitOptions<string> | null
): Promise<string>Fetches the cross-chain operationId based on a transaction linker. Tries each endpoint in sequence until successful.
Parameters:
transactionLinker: Transaction linker object containing sharding informationwaitOptions(optional):undefined(default): Uses default retry settings (30 attempts, 10s delay, 5min timeout)null: Single attempt, no retriesWaitOptionsobject: Custom retry configuration
Returns: Operation ID string (empty string if not found)
Note: Returns an empty string if the operation ID has not been assigned yet. Use waitOptions with a custom successCheck to wait for a non-empty result.
getOperationIdByTransactionHash(
transactionHash: string,
waitOptions?: WaitOptions<string>
): Promise<string>Fetches the cross-chain operationId by a transaction hash. The hash can be either an ETH-style hash (0x... 32 bytes) or a TON hash. The tracker automatically routes the request to the correct underlying API.
Parameters:
transactionHash: TAC (EVM) or TON transaction hashwaitOptions(optional): Wait configuration for automatic retrying
Returns: Operation ID string (empty string if not found)
Note: Returns an empty string if the operation ID has not been assigned yet. Use waitOptions with a custom successCheck to wait for a non-empty result.
getSimplifiedOperationStatus(transactionLinker: TransactionLinker): Promise<SimplifiedStatuses>Gets a simplified status for an operation based on its transaction linker. This method combines multiple queries internally to determine the overall operation state.
Parameters:
transactionLinker: Transaction linker object containing sharding information
Returns: SimplifiedStatuses
Status Logic:
OPERATION_ID_NOT_FOUND: Operation ID not yet assignedPENDING: Operation type is PENDING or UNKNOWNFAILED: Operation type is ROLLBACKSUCCESSFUL: Operation completed successfully
Internal Process:
- Fetches operation ID using the transaction linker
- If no operation ID, returns
OPERATION_ID_NOT_FOUND - Fetches operation type
- Maps operation type to simplified status
getOperationStatus(
operationId: string,
waitOptions?: WaitOptions<StatusInfo>
): Promise<StatusInfo>Retrieves detailed status information for a single operation.
Parameters:
operationId: The operation ID to querywaitOptions(optional): Wait configuration for automatic retrying
Returns: StatusInfo
Note: This method internally calls getOperationStatuses with a single operation ID and extracts the result.
getOperationStatuses(
operationIds: string[],
waitOptions?: WaitOptions<StatusInfosByOperationId>,
chunkSize?: number
): Promise<StatusInfosByOperationId>Retrieves status information for multiple operations in a single call. Processes requests in chunks for better performance.
Parameters:
operationIds: Array of operation IDs to querywaitOptions(optional): Wait configuration for automatic retryingchunkSize(optional): Number of items to process per request (default: 100)
Returns: StatusInfosByOperationId
getStageProfiling(
operationId: string,
waitOptions?: WaitOptions<ExecutionStages>
): Promise<ExecutionStages>Retrieves detailed execution stage information for a single operation. Useful for debugging or understanding delays in cross-chain flow.
Parameters:
operationId: The operation ID to querywaitOptions(optional): Wait configuration for automatic retrying
Returns: ExecutionStages
Note: This method internally calls getStageProfilings with a single operation ID and extracts the result.
getStageProfilings(
operationIds: string[],
waitOptions?: WaitOptions<ExecutionStagesByOperationId>,
chunkSize?: number
): Promise<ExecutionStagesByOperationId>Retrieves execution stage profiling information for multiple operations. Processes requests in chunks for better performance.
Parameters:
operationIds: Array of operation IDs to querywaitOptions(optional): Wait configuration for automatic retryingchunkSize(optional): Number of items to process per request (default: 100)
Returns: ExecutionStagesByOperationId
getOperationType(
operationId: string,
waitOptions?: WaitOptions<OperationType>
): Promise<OperationType>Retrieves the operation type classification for a given operation ID.
Parameters:
operationId: The operation ID to querywaitOptions(optional): Wait configuration for automatic retrying
Returns: OperationType
getOperationIdsByShardsKeys(
shardsKeys: string[],
caller: string,
waitOptions?: WaitOptions<OperationIdsByShardsKey>,
chunkSize?: number
): Promise<OperationIdsByShardsKey>Maps TON shard keys (with caller address) to operation IDs. Processes requests in chunks for better performance.
Parameters:
shardsKeys: Array of shard keys to querycaller: Caller's addresswaitOptions(optional): Wait configuration for automatic retryingchunkSize(optional): Number of items to process per request (default: 100)
Returns: OperationIdsByShardsKey
convertCurrency(
params: ConvertCurrencyParams,
waitOptions?: WaitOptions<ConvertedCurrencyResult>
): Promise<ConvertedCurrencyResult>Converts currency amount using the tracker service with automatic failover across multiple sequencer endpoints.
Parameters:
params:ConvertCurrencyParams- Parameters for currency conversionwaitOptions(optional): Wait configuration for automatic retrying
Returns: ConvertedCurrencyResult
simulateTACMessage(
params: TACSimulationParams,
waitOptions?: WaitOptions<TACSimulationResult>
): Promise<TACSimulationResult>Simulates TAC message execution without broadcasting it on-chain. Useful for estimating fees and validating transaction inputs before sending real transactions.
Parameters:
params:TACSimulationParams- Simulation request with encoded message and contextwaitOptions(optional): Wait configuration for automatic retrying
Returns: TACSimulationResult
getTVMExecutorFee(
params: GetTVMExecutorFeeParams,
waitOptions?: WaitOptions<SuggestedTVMExecutorFee>
): Promise<SuggestedTVMExecutorFee>Calculates suggested TVM executor fee for cross-chain operations with automatic failover across multiple sequencer endpoints.
Parameters:
params:GetTVMExecutorFeeParams- Parameters for fee calculationwaitOptions(optional): Wait configuration for automatic retrying
Returns: SuggestedTVMExecutorFee