WDK logoWDK documentation

Fiat MoonPay Configuration

Configuration options for the @tetherto/wdk-protocol-fiat-moonpay module

Configuration

This page covers all configuration options for the MoonPay fiat module, including optional URL signing and environment selection.

Prerequisites

Before using this module, you need:

  1. A MoonPay developer account - Create an account on MoonPay Dashboard
  2. A publishable API key from your dashboard
  3. If you want signed widget URLs, a trusted backend signing endpoint for the signUrl callback

Installation

npm install @tetherto/wdk-protocol-fiat-moonpay

Basic Configuration

import MoonPayProtocol from '@tetherto/wdk-protocol-fiat-moonpay';

const moonpay = new MoonPayProtocol(walletAccount, {
  apiKey: 'pk_live_xxxxx', // Your MoonPay publishable API key
  signUrl: async (urlForSignature) => {
    const response = await fetch('/api/moonpay/sign-url', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ urlForSignature }),
    });

    if (!response.ok) {
      throw new Error(`Failed to sign MoonPay URL: ${response.status} ${response.statusText}`);
    }

    const { signedUrl } = await response.json();

    return signedUrl;
  },
  environment: 'sandbox',
});

Configuration Options

OptionTypeRequiredDefaultDescription
apiKeystringYes-Your MoonPay publishable API key
signUrlfunctionNo-Callback used to sign buy and sell widget URLs through a trusted backend
cacheTimenumberNo600000 (10 min)Duration in milliseconds to cache supported currencies
environment'production' | 'sandbox'NoproductionMoonPay widget URL endpoint set

Constructor Overloads

The MoonPayProtocol class supports three constructor patterns:

// Without account (for public read operations like fetching supported currencies)
const moonpay = new MoonPayProtocol(undefined, config);

// With read-only account
const moonpay = new MoonPayProtocol(readOnlyAccount, config);

// With full wallet account (for buy/sell operations)
const moonpay = new MoonPayProtocol(walletAccount, config);

Environment Configuration

Sandbox (Testing)

Use sandbox endpoints for development and testing:

const moonpay = new MoonPayProtocol(walletAccount, {
  apiKey: 'pk_test_xxxxx',
  signUrl: async (urlForSignature) => {
    const response = await fetch('/api/moonpay/sign-url', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ urlForSignature }),
    });

    return (await response.json()).signedUrl;
  },
  environment: 'sandbox',
});

In sandbox mode:

  • No real transactions are processed
  • Use test card numbers provided by MoonPay
  • KYC verification is simulated

If you do not need signed URLs, omit signUrl and the protocol returns unsigned widget URLs directly.

Production

For production deployments, use live API keys and the production endpoint set:

const moonpay = new MoonPayProtocol(walletAccount, {
  apiKey: 'pk_live_xxxxx',
  signUrl: async (urlForSignature) => {
    const response = await fetch('/api/moonpay/sign-url', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ urlForSignature }),
    });

    return (await response.json()).signedUrl;
  },
  environment: 'production',
});

Widget Customization

When calling buy() or sell(), you can customize the MoonPay widget appearance:

const result = await moonpay.buy({
  cryptoAsset: 'eth',
  fiatCurrency: 'usd',
  fiatAmount: 10000n, // $100.00 in cents
  config: {
    colorCode: '#3B82F6',       // Your brand color (hex)
    theme: 'dark',              // 'dark' or 'light'
    language: 'en',             // ISO 639-1 language code
    redirectURL: 'https://yourapp.com/callback',
  },
});

Available Buy Widget Options

OptionTypeDescription
colorCodestringHexadecimal color for widget accent
theme'dark' | 'light'Widget appearance theme
themeIdstringID of a custom theme
languagestringISO 639-1 language code
showAllCurrenciesbooleanShow all supported cryptocurrencies
showOnlyCurrenciesstringComma-separated currency codes to display
showWalletAddressFormbooleanShow wallet address input form
redirectURLstringURL to redirect after completion
unsupportedRegionRedirectUrlstringURL for unsupported regions
skipUnsupportedRegionScreenbooleanSkip unsupported region screen
defaultCurrencyCodestringPre-selected cryptocurrency code
walletAddressstringPre-filled wallet address
walletAddressTagstringWallet address memo/tag (for EOS, XRP, etc.)
walletAddressesstringJSON string of wallet addresses for multiple currencies
walletAddressTagsstringJSON string of address tags for multiple currencies
contractAddressstringToken contract address (DeFi Buy only)
networkCodestringNetwork for the token contract (DeFi Buy only)
lockAmountbooleanPrevent user from changing amount
emailstringPre-fill customer email
externalTransactionIdstringYour transaction identifier
externalCustomerIdstringYour customer identifier
paymentMethodstringPre-select payment method

Available Sell Widget Options

For sell(), the widget config uses MoonPaySellParams with different options:

OptionTypeDescription
colorCodestringHexadecimal color for widget accent
theme'dark' | 'light'Widget appearance theme
themeIdstringID of a custom theme
languagestringISO 639-1 language code
showAllCurrenciesbooleanShow all supported cryptocurrencies
showOnlyCurrenciesstringComma-separated currency codes to display
showWalletAddressFormbooleanShow wallet address input form
redirectURLstringURL to redirect after completion
unsupportedRegionRedirectUrlstringURL for unsupported regions
skipUnsupportedRegionScreenbooleanSkip unsupported region screen
defaultBaseCurrencyCodestringPre-selected cryptocurrency to sell
refundWalletAddressesstringJSON string of wallet addresses for refunds
lockAmountbooleanPrevent user from changing amount
emailstringPre-fill customer email
externalTransactionIdstringYour transaction identifier
externalCustomerIdstringYour customer identifier
paymentMethodstringPre-select payout method

Next Steps

On this page