Skip to main content

Documentation Index

Fetch the complete documentation index at: https://dev.moonpay.com/llms.txt

Use this file to discover all available pages before exploring further.

Use this method to fetch a single transaction by its ID, including its stage breakdown. Call it after a payment flow completes (for example, when client.setupApplePay(), client.setupGooglePay(), or client.setupBuy() emits complete) to poll for the final transaction status. For request and response details, see the Get a transaction API.
Get a transaction
import { createClient } from "@moonpay/platform-sdk-web";

const client = createClient({ sessionToken: "c3N0XzAwMQ==" });

const result = await client.getTransaction("tr_abc123");

if (!result.ok) {
  // Handle error
  console.error(result.error.code, result.error.message);
  return;
}

console.log(result.value.data);

Parameters

client.getTransaction() takes a single positional argument.
ArgumentTypeRequiredDescription
idstringThe MoonPay ID of the transaction.
This method does not require a separate auth token. The client uses stored credentials from an active connection.

Result

client.getTransaction() returns a Result<{ data: TransactionWithStages }, GetTransactionsError>.

Result envelope

Result<{ data: TransactionWithStages }, GetTransactionsError>
FieldTypeRequiredDescription
okbooleanWhether the operation succeeded.
value{ data: TransactionWithStages }Present when ok is true.
errorGetTransactionsErrorPresent when ok is false.

TransactionWithStages

A transaction with its stage breakdown. See the Transaction object for every field, and the Get a transaction API for the response shape.
FieldTypeRequiredDescription
idstringThe MoonPay ID of the transaction.
statusTransactionStatusThe current transaction status. See the Transaction object for the full list of statuses.
sourceobjectThe source amount and asset (fiat currency).
destinationobjectThe destination amount and asset (cryptocurrency).
createdAtstringAn ISO 8601 timestamp of when the transaction was created.
stagesStage[]The transaction’s pipeline stages, each with a kind and status.

GetTransactionsError

GetTransactionsError is the standard MoonPay Platform API error shape, DevPlatformApiError.
FieldTypeRequiredDescription
codeDevPlatformApiErrorCodeA machine-readable error code (for example, "not_found", "unauthorized"). See the error reference for the full list.
messagestringA developer-friendly message.
errorsDevPlatformApiErrorDetail[]Optional list of field-level errors.

Example: poll until terminal status

After a payment flow emits complete, poll client.getTransaction() until the transaction reaches a terminal status. The set of terminal statuses depends on the flow — check the Transaction object reference for the values that apply.
Poll for final status
const TERMINAL_STATUSES = new Set(["completed", "failed"]);

async function pollTransaction(transactionId: string) {
  while (true) {
    const result = await client.getTransaction(transactionId);

    if (!result.ok) {
      throw new Error(result.error.message);
    }

    const transaction = result.value.data;

    if (TERMINAL_STATUSES.has(transaction.status)) {
      return transaction;
    }

    await new Promise((resolve) => setTimeout(resolve, 3000));
  }
}
Webhook support is coming soon. Until then, use polling to track transaction status.