WDK logoWDK documentation

API Reference

API Reference for the @tetherto/wdk-protocol-fiat-moonpay module

Complete API documentation for the @tetherto/wdk-protocol-fiat-moonpay module.

Constructor

new MoonPayProtocol(account, config)

Creates a new MoonPayProtocol instance.

Parameters:

NameTypeDescription
accountIWalletAccount | IWalletAccountReadOnly | undefinedWallet account for transactions
configMoonPayProtocolConfigConfiguration object

Config Options:

NameTypeRequiredDefaultDescription
apiKeystringYes-Your MoonPay publishable API key
secretKeystringYes-Your MoonPay secret key
cacheTimenumberNo600000Cache duration for currencies (ms)

Example:

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

const moonpay = new MoonPayProtocol(walletAccount, {
  apiKey: 'pk_live_xxxxx',
  secretKey: 'sk_live_xxxxx',
});

Methods

buy(options)

Generates a signed widget URL for purchasing cryptocurrency.

Parameters:

NameTypeRequiredDescription
options.cryptoAssetstringYesCryptocurrency code (e.g., 'eth', 'btc')
options.fiatCurrencystringYesFiat currency code (e.g., 'usd', 'eur')
options.cryptoAmountbigintNo*Amount in smallest crypto units
options.fiatAmountbigintNo*Amount in smallest fiat units (cents)
options.recipientstringNoWallet address (uses account address if not provided)
options.configMoonPayBuyParamsNoWidget configuration options

*Either cryptoAmount or fiatAmount must be provided, but not both.

Returns: Promise<{ buyUrl: string }>


sell(options)

Generates a signed widget URL for selling cryptocurrency.

Parameters:

NameTypeRequiredDescription
options.cryptoAssetstringYesCryptocurrency code
options.fiatCurrencystringYesFiat currency code
options.cryptoAmountbigintNo*Amount in smallest crypto units
options.fiatAmountbigintNo*Amount in smallest fiat units
options.refundAddressstringNoRefund wallet address
options.configMoonPaySellParamsNoWidget configuration options

Returns: Promise<{ sellUrl: string }>


quoteBuy(options)

Gets a price quote for a cryptocurrency purchase.

Parameters:

NameTypeRequiredDescription
options.cryptoAssetstringYesCryptocurrency code
options.fiatCurrencystringYesFiat currency code
options.cryptoAmountbigintNo*Amount in smallest crypto units
options.fiatAmountbigintNo*Amount in smallest fiat units
options.configMoonPayQuoteBuyParamsNoQuote parameters

Returns: Promise<MoonPayBuyQuote>

{
  cryptoAmount: bigint,  // Crypto amount you'll receive
  fiatAmount: bigint,    // Fiat amount to pay
  fee: bigint,           // Total fee amount
  rate: string,          // Exchange rate
  metadata: MoonPayBuyQuoteMetadata
}

quoteSell(options)

Gets a price quote for selling cryptocurrency.

Parameters:

NameTypeRequiredDescription
options.cryptoAssetstringYesCryptocurrency code
options.fiatCurrencystringYesFiat currency code
options.cryptoAmountbigintYesAmount in smallest crypto units
options.configMoonPayQuoteSellParamsNoQuote parameters

Returns: Promise<MoonPaySellQuote>

{
  cryptoAmount: bigint,  // Crypto amount to sell
  fiatAmount: bigint,    // Fiat amount you'll receive
  fee: bigint,           // Total fee amount
  rate: string,          // Exchange rate
  metadata: MoonPaySellQuoteMetadata
}

getSupportedCryptoAssets()

Fetches the list of supported cryptocurrencies. Results are cached.

Returns: Promise<MoonPaySupportedCryptoAsset[]>

{
  code: string,          // Currency code (e.g., 'eth')
  decimals: number,      // Decimal places
  networkCode: string,   // Network identifier
  name: string,          // Display name
  metadata: MoonPayCryptoCurrencyDetails
}

getSupportedFiatCurrencies()

Fetches the list of supported fiat currencies. Results are cached.

Returns: Promise<MoonPaySupportedFiatCurrency[]>

{
  code: string,          // Currency code (e.g., 'usd')
  decimals: number,      // Decimal places
  name: string,          // Display name
  metadata: MoonPayFiatCurrencyDetails
}

getSupportedCountries()

Fetches the list of supported countries.

Returns: Promise<MoonPaySupportedCountry[]>

{
  code: string,          // ISO country code
  name: string,          // Country name
  isBuyAllowed: boolean, // Buy operations allowed
  isSellAllowed: boolean,// Sell operations allowed
  metadata: MoonPayCountryDetail
}

getTransactionDetail(txId, direction?)

Retrieves details of a specific transaction.

Parameters:

NameTypeRequiredDefaultDescription
txIdstringYes-MoonPay transaction ID
direction'buy' | 'sell'No'buy'Transaction type

Returns: Promise<MoonPayTransactionDetail>

{
  status: 'completed' | 'failed' | 'in_progress',
  cryptoAsset: string,
  fiatCurrency: string,
  metadata: MoonPayBuyTransaction | MoonPaySellTransaction
}

Types

MoonPayProtocolConfig

interface MoonPayProtocolConfig {
  apiKey: string;
  secretKey: string;
  cacheTime?: number;
}

MoonPayBuyParams / MoonPaySellParams

Widget configuration options:

interface MoonPayBuyParams {
  colorCode?: string;
  theme?: 'dark' | 'light';
  themeId?: string;
  language?: string;
  showAllCurrencies?: boolean;
  showOnlyCurrencies?: string;
  showWalletAddressForm?: boolean;
  redirectURL?: string;
  unsupportedRegionRedirectUrl?: string;
  skipUnsupportedRegionScreen?: boolean;
  lockAmount?: boolean;
  email?: string;
  externalTransactionId?: string;
  externalCustomerId?: string;
  paymentMethod?: string;
}

MoonPayQuoteBuyParams

interface MoonPayQuoteBuyParams {
  extraFeePercentage?: number;  // 0-10%
  paymentMethod?: string;
  areFeesIncluded?: boolean;
  walletAddress?: string;
}

MoonPayQuoteSellParams

interface MoonPayQuoteSellParams {
  extraFeePercentage?: number;  // 0-10%
  payoutMethod?: string;
}

Next Steps

On this page