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)
new MoonPayProtocol(account, config)Creates a new MoonPayProtocol instance.
Parameters:
account
IWalletAccount | IWalletAccountReadOnly | undefined
Wallet account for transactions
config
MoonPayProtocolConfig
Configuration object
Config Options:
apiKey
string
Yes
-
Your MoonPay publishable API key
secretKey
string
Yes
-
Your MoonPay secret key
cacheTime
number
No
600000
Cache 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)
buy(options)Generates a signed widget URL for purchasing cryptocurrency.
Parameters:
options.cryptoAsset
string
Yes
Cryptocurrency code (e.g., 'eth', 'btc')
options.fiatCurrency
string
Yes
Fiat currency code (e.g., 'usd', 'eur')
options.cryptoAmount
bigint
No*
Amount in smallest crypto units
options.fiatAmount
bigint
No*
Amount in smallest fiat units (cents)
options.recipient
string
No
Wallet address (uses account address if not provided)
options.config
MoonPayBuyParams
No
Widget configuration options
*Either cryptoAmount or fiatAmount must be provided, but not both.
Returns: Promise<{ buyUrl: string }>
sell(options)
sell(options)Generates a signed widget URL for selling cryptocurrency.
Parameters:
options.cryptoAsset
string
Yes
Cryptocurrency code
options.fiatCurrency
string
Yes
Fiat currency code
options.cryptoAmount
bigint
No*
Amount in smallest crypto units
options.fiatAmount
bigint
No*
Amount in smallest fiat units
options.refundAddress
string
No
Refund wallet address
options.config
MoonPaySellParams
No
Widget configuration options
Returns: Promise<{ sellUrl: string }>
quoteBuy(options)
quoteBuy(options)Gets a price quote for a cryptocurrency purchase.
Parameters:
options.cryptoAsset
string
Yes
Cryptocurrency code
options.fiatCurrency
string
Yes
Fiat currency code
options.cryptoAmount
bigint
No*
Amount in smallest crypto units
options.fiatAmount
bigint
No*
Amount in smallest fiat units
options.config
MoonPayQuoteBuyParams
No
Quote parameters
Returns: Promise<MoonPayBuyQuote>
quoteSell(options)
quoteSell(options)Gets a price quote for selling cryptocurrency.
Parameters:
options.cryptoAsset
string
Yes
Cryptocurrency code
options.fiatCurrency
string
Yes
Fiat currency code
options.cryptoAmount
bigint
Yes
Amount in smallest crypto units
options.config
MoonPayQuoteSellParams
No
Quote parameters
Returns: Promise<MoonPaySellQuote>
getSupportedCryptoAssets()
getSupportedCryptoAssets()Fetches the list of supported cryptocurrencies. Results are cached.
Returns: Promise<MoonPaySupportedCryptoAsset[]>
getSupportedFiatCurrencies()
getSupportedFiatCurrencies()Fetches the list of supported fiat currencies. Results are cached.
Returns: Promise<MoonPaySupportedFiatCurrency[]>
getSupportedCountries()
getSupportedCountries()Fetches the list of supported countries.
Returns: Promise<MoonPaySupportedCountry[]>
getTransactionDetail(txId, direction?)
getTransactionDetail(txId, direction?)Retrieves details of a specific transaction.
Parameters:
txId
string
Yes
-
MoonPay transaction ID
direction
'buy' | 'sell'
No
'buy'
Transaction type
Returns: Promise<MoonPayTransactionDetail>
Types
MoonPayProtocolConfig
MoonPayProtocolConfigMoonPayBuyParams / MoonPaySellParams
MoonPayBuyParams / MoonPaySellParamsWidget configuration options:
MoonPayQuoteBuyParams
MoonPayQuoteBuyParamsMoonPayQuoteSellParams
MoonPayQuoteSellParamsNext Steps
Configuration - Setup and configuration options
Usage Guide - Common usage patterns

