Vana SDK - v2.2.2
    Preparing search index...

    Class OperationsController

    Controller for managing asynchronous operations.

    This controller provides methods to check the status of pending operations and recover from interrupted transactions.

    // Recover an orphaned operation
    try {
    const result = await vana.permissions.grant(...);
    } catch (error) {
    if (error instanceof TransactionPendingError) {
    // Save the operation ID
    localStorage.setItem('pendingOp', error.operationId);

    // Later, check the status
    const operationId = localStorage.getItem('pendingOp');
    const status = await vana.operations.getStatus(operationId);

    if (status.type === 'confirmed') {
    console.log('Transaction confirmed:', status.receipt);
    }
    }
    }

    Hierarchy

    • BaseController
      • OperationsController
    Index

    Methods

    • Gets the current status of an operation.

      Parameters

      • operationId: string

        The unique identifier of the operation to check

      Returns Promise<OperationStatus>

      Promise resolving to the current operation status

      This method allows recovery of operations that were interrupted due to:

      • Browser tab closure
      • Network disconnection
      • Application errors
      • Timeout during polling

      The method queries the backend for the current operation state without starting a new polling session.

      When relayer is not configured

      When operation is not found

      const status = await vana.operations.getStatus('550e8400-e29b-41d4-a716-446655440000');

      switch(status.type) {
      case 'pending':
      console.log('Still processing...');
      break;
      case 'queued':
      console.log(`Position in queue: ${status.position}`);
      break;
      case 'confirmed':
      console.log(`Transaction confirmed: ${status.receipt.transactionHash}`);
      break;
      case 'failed':
      console.error(`Operation failed: ${status.error}`);
      break;
      }
    • Waits for an operation to complete and returns the final result.

      Parameters

      • operationId: string

        The unique identifier of the operation to wait for

      • Optionaloptions: {
            signal?: AbortSignal;
            onStatusUpdate?: (status: OperationStatus) => void;
            timeout?: number;
            initialInterval?: number;
            maxInterval?: number;
        }

        Optional configuration for polling behavior

      Returns Promise<{ hash: string; receipt?: any }>

      Promise resolving when the operation is confirmed

      This method is useful for resuming polling of an operation that was previously interrupted. Unlike getStatus, this method will actively poll until the operation reaches a final state (confirmed or failed).

      When polling times out

      When the operation fails

      // Resume polling with status updates
      const result = await vana.operations.waitForConfirmation(operationId, {
      onStatusUpdate: (status) => {
      console.log(`Current status: ${status.type}`);
      },
      timeout: 600000 // 10 minutes
      });

      console.log('Transaction confirmed:', result.hash);
    • Cancels a pending operation if supported by the backend.

      Parameters

      • _operationId: string

      Returns Promise<boolean>

      Promise resolving to true if cancellation was successful

      Not all backends support operation cancellation. This method will attempt to cancel the operation but success is not guaranteed.

      When cancellation is not supported or fails

      try {
      const cancelled = await vana.operations.cancel(operationId);
      if (cancelled) {
      console.log('Operation cancelled successfully');
      }
      } catch (error) {
      console.error('Failed to cancel operation:', error);
      }
    • Processes queued operations from the operation store.

      Parameters

      • config: {
            operationStore: IOperationStore;
            atomicStore: IAtomicStore;
            walletClient: {};
            publicClient: {};
            maxOperations?: number;
            maxRetries?: number;
            gasEscalationFactor?: number;
            maxGasMultiplier?: number;
            onOperationComplete?: (operationId: string, success: boolean) => void;
            onError?: (operationId: string, error: Error) => void;
        }

        Configuration for queue processing

      Returns Promise<
          {
              processed: number;
              succeeded: number;
              failed: number;
              errors: { operationId: string; error: string }[];
          },
      >

      Promise resolving to processing results

      This method is designed for worker processes that handle asynchronous operation processing. It fetches queued operations, processes them with proper nonce management and gas escalation, and handles retries.

      This is typically called from a background worker or cron job to process operations that were queued for asynchronous execution.

      // In a worker process
      const results = await vana.operations.processQueue({
      operationStore,
      atomicStore,
      walletClient,
      publicClient,
      maxOperations: 10,
      onOperationComplete: (id, success) => {
      console.log(`Operation ${id}: ${success ? 'completed' : 'failed'}`);
      }
      });

      console.log(`Processed ${results.processed} operations`);
    • Burns a stuck nonce by sending a minimal self-transfer.

      Parameters

      • config: {
            walletClient: {};
            publicClient: {};
            atomicStore: IAtomicStore;
            address: `0x${string}`;
            stuckNonce: number;
        }

        Configuration for nonce burning

      Returns Promise<string>

      Promise resolving to the burn transaction hash

      This method is used to unblock the transaction queue when a transaction is stuck. It sends a minimal amount to the same address with the stuck nonce and higher gas to ensure it gets mined.

      const hash = await vana.operations.burnStuckNonce({
      walletClient,
      publicClient,
      atomicStore,
      address: relayerAddress,
      stuckNonce: 42
      });

      console.log(`Burned stuck nonce with tx: ${hash}`);