Skip to main content

cancelCheckoutTransaction

Cancels a checkout transaction before it has been broadcast to the blockchain. Once cancelled, the transaction cannot be resumed — create a new one to start over.

Usage

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

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

console.log('Status:', transaction.executionState); // 'cancelled'

Parameters

ParameterTypeDescription
transactionIdstringThe checkout transaction ID to cancel.

Returns

Promise<CheckoutTransaction> - The cancelled transaction object.

Examples

Cancel on user action

import {
  cancelCheckoutTransaction,
  createCheckoutTransaction,
} from '@dynamic-labs-sdk/client';

const CancelButton = ({ transactionId, onReset }) => {
  const handleCancel = async () => {
    await cancelCheckoutTransaction({ transactionId });
    onReset();
  };

  return <button onClick={handleCancel}>Cancel Transaction</button>;
};
This example uses React; the JavaScript SDK is framework-agnostic and can be used with any frontend or in Node.

Cancel on wallet rejection

If a user rejects the signing request in their wallet, cancel the transaction to clean up:
import {
  submitCheckoutTransaction,
  cancelCheckoutTransaction,
} from '@dynamic-labs-sdk/client';

try {
  await submitCheckoutTransaction({
    transactionId,
    walletAccount,
  });
} catch (error) {
  if (error.message.includes('rejected')) {
    await cancelCheckoutTransaction({ transactionId });
    console.log('Transaction cancelled after user rejection');
  }
}

Notes

  • Only transactions that have not yet been broadcast can be cancelled
  • Cancelling clears the session token associated with the transaction
  • After cancellation, you must create a new transaction to restart the flow