Skip to main content

getCheckoutTransaction

Fetches the current state of a checkout transaction. Use this to poll for status updates after submitting a transaction, or to restore transaction state on page reload.

Usage

import { getCheckoutTransaction } from '@dynamic-labs-sdk/client';

const transaction = await getCheckoutTransaction({
  transactionId: 'txn_abc123',
});

console.log('Execution state:', transaction.executionState);
console.log('Settlement state:', transaction.settlementState);

Parameters

ParameterTypeDescription
transactionIdstringThe checkout transaction ID returned by createCheckoutTransaction.

Returns

Promise<CheckoutTransaction> - The current transaction state.

Execution States

StateDescription
pendingTransaction has been created but not yet signed
signingTransaction is being signed by the wallet
broadcastedTransaction has been broadcast to the blockchain
source_confirmedSource chain has confirmed the transaction
cancelledTransaction was cancelled before broadcast
expiredTransaction expired before completion
failedTransaction failed during execution

Settlement States

StateDescription
noneNo settlement in progress
bridgingFunds are being bridged across chains
routingTransaction is being routed through a DEX
settlingFunds are settling to the destination
swappingToken swap is in progress
completedSettlement is complete
failedSettlement failed

Examples

Poll for completion

import { getCheckoutTransaction } from '@dynamic-labs-sdk/client';

const TERMINAL_STATES = ['cancelled', 'expired', 'failed'];
const TERMINAL_SETTLEMENT = ['completed', 'failed'];

const pollTransaction = async (transactionId) => {
  const poll = async () => {
    const tx = await getCheckoutTransaction({ transactionId });

    if (
      TERMINAL_STATES.includes(tx.executionState) ||
      TERMINAL_SETTLEMENT.includes(tx.settlementState)
    ) {
      return tx;
    }

    // Wait 3 seconds and poll again
    await new Promise((resolve) => setTimeout(resolve, 3000));
    return poll();
  };

  return poll();
};

const finalTx = await pollTransaction('txn_abc123');
console.log('Final state:', finalTx.settlementState);

Restore transaction on page reload

import { getCheckoutTransaction } from '@dynamic-labs-sdk/client';

const restoreCheckout = async () => {
  const storedId = localStorage.getItem('checkoutTransactionId');
  if (!storedId) return null;

  try {
    const transaction = await getCheckoutTransaction({
      transactionId: storedId,
    });
    return transaction;
  } catch {
    // Transaction no longer valid
    localStorage.removeItem('checkoutTransactionId');
    return null;
  }
};