Render the Buy button frame into your UI. The frame renders a payment button — card, Apple Pay, or Google Pay, depending on what’s available — and runs the buy pipeline on tap. Use it when you want a single payment button instead of orchestrating individual payment-method frames yourself.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.
Like the headless Buy frame, the buy
button can emit a
challenge event mid-pipeline. Render a separate challenge
frame using
client.setupChallenge() at
the URL from the event payload.Setup buy button
Parameters
| Property | Type | Required | Description |
|---|---|---|---|
quote | string | ✅ | The quote signature returned from getQuote. |
container | HTMLElement | ✅ | A DOM element to render the buy button into. |
onEvent | (event: BuyButtonEvent) => void | Callback invoked for buy-button events. See BuyButtonEvent. |
BuyButtonEvent
onEvent receives events as the buy pipeline progresses. Unlike setupBuy(), the buy-button frame does not emit a ready event — the button renders synchronously and there is nothing to wait for before showing it.
| kind | Payload | When you receive it |
|---|---|---|
"complete" | { transaction: FrameTransaction } | The pipeline finished. Inspect the FrameTransaction to detect the failure variant. |
"challenge" | { kind: string; url: string } | Verification is required before the transaction can proceed. Render the challenge frame at the provided url. |
"error" | BuyButtonEventError | The flow encountered an error. Surface to logs and tear down the frame. |
FrameTransaction
FrameTransaction is a discriminated union — the failure variant carries failureReason, the non-failure variant always carries id. Pass id to client.getTransaction() to poll for the final status.
| Field | Type | Required | Description |
|---|---|---|---|
status | string | ✅ | The transaction status. On the failure variant, "failed". |
id | string | Required on the non-failure variant; optional when status is "failed". | |
failureReason | string | Present only on the failure variant (status === "failed"). |
BuyButtonEventError
| Field | Type | Required | Description |
|---|---|---|---|
code | string | ✅ | The error category. Includes configurationError, invalidQuote, and backend-specific error codes. |
message | string | ✅ | Developer-friendly details. Not intended to be rendered in UI. |
Result
client.setupBuyButton() returns a Result<BuyButtonFrame, SetupBuyButtonError>.
Result envelope
Result<BuyButtonFrame, SetupBuyButtonError>
| Field | Type | Required | Description |
|---|---|---|---|
ok | boolean | ✅ | Whether the operation succeeded. |
value | BuyButtonFrame | Present when ok is true. | |
error | SetupBuyButtonError | Present when ok is false. |
BuyButtonFrame
| Field | Type | Required | Description |
|---|---|---|---|
setQuote | (signature: string) => void | ✅ | Updates the quote signature used by the frame. Use this when the current quote expires before the customer taps the button — fetch a new quote and pass its signature. |
dispose | () => void | ✅ | Unmounts the frame. After you call this, no further events are dispatched to your onEvent callback. |
SetupBuyButtonError
| Field | Type | Required | Description |
|---|---|---|---|
kind | "configurationError" | "genericError" | ✅ | The error category. |
message | string | ✅ | Developer-friendly details. |
TS Definitions
TS Definitions
types.ts