← Back to Blog
Engineering22.01.2026·5 min read

Embedding a Crypto Payment Widget: Frontend Integration Guide

A pre-built payment widget handles wallet connection, token selection, and transaction confirmation so you do not have to build crypto checkout from scratch. Embedded widgets achieve 34% higher completion rates than redirect-based flows.

Quick Answer

A crypto payment widget is a pre-built user interface component that handles the entire cryptocurrency checkout flow. It connects to the customer's wallet, displays supported tokens and networks, calculates real-time exchange rates, and manages the transaction lifecycle from initiation through co...

Adding crypto payments to a checkout page sounds straightforward until you start building it. Wallet connection protocols differ by chain. Token approval flows vary by standard. Exchange rates fluctuate by the second. Confirmation UIs need to communicate complex blockchain states to non-technical customers. A crypto payment widget encapsulates all of this complexity into a single embeddable component that drops into your existing checkout page. The merchant provides an amount and a callback URL; the widget handles everything else. Data from SpacePay's merchant integrations shows that embedded widgets achieve a 34% higher payment completion rate compared to redirect-based checkout flows, where the customer leaves your site to complete payment on a third-party page.

Four Integration Approaches

Payment widget providers typically offer multiple integration methods to accommodate different tech stacks and customisation needs. Each approach has distinct trade-offs.

MethodComplexityCustomisationSecurityConversion
Iframe embedLowLimitedHigh (sandboxed)Good
JavaScript SDKMediumModerateMedium (same-origin)Better
React / Vue componentMedium-HighFullMedium (same-origin)Best
Hosted redirectLowMinimalHigh (isolated)Lowest

Iframe Embed

The simplest integration. You add an <iframe> tag pointing to the payment provider's hosted widget, passing payment parameters as URL query strings or through a server-generated session ID. The widget runs in a sandboxed environment completely isolated from your page's DOM, cookies, and JavaScript context. Communication happens through the postMessage API, where the iframe emits events like payment status updates and the parent page listens for them. The limitation is customisation — you can typically only control colours and logo through URL parameters, and the widget's layout is fixed.

JavaScript SDK

A step up in flexibility. You include a <script> tag that loads the payment provider's SDK, then call an initialisation function with a configuration object specifying the target DOM element, payment amount, supported currencies, theme options, and callback functions. The SDK renders the widget directly into your page's DOM, giving you more control over placement, sizing, and styling. Event callbacks fire as JavaScript functions rather than postMessage events, making them easier to integrate with your existing application logic. The trade-off is that the SDK runs in the same JavaScript context as your page, so you need to trust the provider's code.

React / Vue Component

The deepest integration for modern frontend stacks. The payment provider publishes a package on npm that exports a typed component with props for configuration and callbacks for events. In React, you import <SpacePayCheckout /> and pass props like amount, currency, onPaymentComplete, and theme. The component manages its own state, renders payment UI within your component tree, and follows React lifecycle conventions. This approach offers full theming control (CSS-in-JS, Tailwind classes, or style props), TypeScript type safety, and the ability to conditionally render or animate the widget using your framework's tools. SpacePay's React component can be integrated in under 30 minutes.

Hosted Redirect

The customer is redirected to a payment page hosted entirely by the provider. After completing payment, they are redirected back to your success or failure URL. This is the simplest to implement — just a server-side API call to create a session and a redirect. But it produces the worst conversion rates because every page transition is a drop-off point. The customer leaves your brand context, waits for a new page to load, and must trust an unfamiliar domain. For crypto-native users who are already wary of phishing, a redirect to a third-party domain can trigger abandonment.

Responsive Design and Mobile Considerations

Over 60% of crypto wallet interactions happen on mobile devices. A payment widget that looks perfect on desktop but breaks on a 375px viewport will lose a significant share of transactions. Key considerations include responsive container sizing (the widget should adapt to its parent's width), touch-friendly tap targets (at least 44x44 pixels for buttons), and proper handling of mobile wallet deep links.

When a customer pays on mobile, the widget needs to open the wallet app (MetaMask, Phantom, Trust Wallet) for transaction signing. This involves deep linking on iOS and Android, which behaves differently across browsers and operating systems. A well-engineered widget handles these edge cases transparently — detecting the customer's environment, opening the correct wallet app, and returning focus to the browser after signing. SpacePay's widget has been tested across all major mobile browsers and wallet combinations to ensure a consistent experience.

Event Callbacks and UI State Management

The widget emits events throughout the payment lifecycle that your frontend should handle to provide a responsive user experience. These are distinct from server-side webhook notifications — callbacks update the UI; webhooks fulfil the order.

  • onReady — The widget has loaded and is ready for interaction. Use this to remove loading skeletons or spinners.
  • onPaymentStart — The customer has initiated the payment (connected wallet, selected token, clicked pay). Disable duplicate pay buttons and show a progress indicator.
  • onPaymentPending — The transaction has been broadcast and is in the mempool. Show a “Transaction detected, waiting for confirmation” message.
  • onPaymentComplete — The transaction has been confirmed on-chain. Show a success state and order confirmation details. Note: always verify via webhooks before fulfilling.
  • onPaymentFailed — The transaction reverted, timed out, or the customer rejected it in their wallet. Show an error state with a retry option.
  • onClose — The customer dismissed the widget without completing payment. Log this for analytics and optionally show a recovery prompt.

A critical principle: never use client-side callbacks as the sole trigger for order fulfilment. A malicious user could spoof callback events. Client callbacks update the UI. Server-side webhooks drive business logic. This separation ensures security without sacrificing user experience.

Security: CSP, Iframe Sandboxing, and Origin Validation

Embedding third-party code on your checkout page introduces a security surface that must be carefully managed.

  • Content Security Policy (CSP). Configure your CSP frame-src directive to only allow the payment provider's domain. For JS SDK integrations, add the provider's CDN to script-src. This prevents any other origin from injecting frames or scripts into your page.
  • Iframe sandboxing. Use the sandbox attribute with only the permissions the widget needs: allow-scripts allow-same-origin allow-popups. Never add allow-top-navigation unless the widget explicitly requires redirect capability.
  • Origin validation. When listening for postMessage events from an iframe, always check event.origin against the expected payment provider domain before processing the message. Ignoring this check is a common XSS vector.
  • HTTPS enforcement. The widget must load over HTTPS. Mixed content (HTTPS page with HTTP iframe) will be blocked by modern browsers. Wallet connection protocols also require a secure context.

Theming and Brand Consistency

A payment widget that looks foreign on your checkout page erodes customer trust. Modern widgets support theme configuration that lets you match your brand identity. SpacePay's widget accepts a theme object with properties for primary colour, background colour, text colour, border radius, font family, and dark/light mode. The goal is that the widget feels like a native part of your checkout rather than a bolted-on third-party element.

For framework component integrations, theming goes deeper. You can apply your own CSS classes, use CSS variables, or pass a Tailwind configuration. Some merchants use the widget in a modal overlay, others inline within the checkout form, and others as a slide-in panel. The component approach accommodates all these patterns because it renders within your component tree rather than in an isolated frame.

Performance Optimisation

Widget load time directly impacts conversion. Every 100ms of delay reduces completion rates measurably. Best practices include lazy loading the widget (defer loading until the customer reaches the payment step), preloading the SDK script with rel="preload", using a CDN-hosted script with proper cache headers, and implementing a loading skeleton that matches the widget's dimensions to prevent layout shift. SpacePay's widget is under 45KB gzipped and loads in under 200ms on a standard 4G connection.

Frequently Asked Questions

What is a crypto payment widget?

A pre-built UI component that handles the entire crypto checkout flow: wallet connection, token selection, exchange rate display, and transaction confirmation. You embed it into your checkout page rather than building payment UI from scratch.

How much does embedding improve conversion vs. redirect?

Embedded widgets achieve approximately 34% higher payment completion rates compared to redirect flows. Keeping the customer on your site eliminates the trust gap and page-load friction that cause abandonment during redirects.

Which integration method should I choose?

If you use React or Vue, choose the framework component for maximum customisation and type safety. If you use a server-rendered stack or vanilla JavaScript, the JS SDK offers a good balance. Iframe is best when you need strict security isolation with minimal development effort. Avoid redirect unless you have no alternative.

How do I secure an iframe payment widget?

Use the sandbox attribute with minimal permissions, set a strict CSP frame-src directive, validate postMessage origins, and enforce HTTPS. Never allow the iframe to access your page's DOM or cookies.

Should I use callbacks or webhooks for order fulfilment?

Use callbacks for frontend UI updates and webhooks for order fulfilment. Client-side callbacks can be spoofed or missed if the browser closes. Server-side webhooks are the authoritative source of truth. This separation ensures both great UX and security.

Can I customise the widget's appearance?

Yes. Most widgets support theming through configuration: colours, fonts, border radius, logo, and dark/light mode. Framework components offer the deepest customisation through CSS overrides or style props. SpacePay's widget supports full brand customisation across all integration methods.

Does SpacePay offer a React component?

Yes. SpacePay provides a React component, a vanilla JavaScript SDK, and an iframe embed option. The React component offers typed props, event callbacks, and full theme customisation, installable via npm with integration typically taking under 30 minutes.

Conclusion

The payment widget is the interface between your checkout experience and the complexity of blockchain transactions. Choosing the right integration method — iframe for simplicity, JS SDK for flexibility, or a React component for full control — determines both conversion rates and development velocity. The 34% completion rate advantage of embedded over redirect is not marginal; it is the difference between a crypto payment option that generates revenue and one that sits unused. Invest in the embed, configure the callbacks, pair with server-side webhooks, and your crypto checkout becomes as reliable as any traditional payment flow.