Usage
How to use the @tetherto/wdk-protocol-fiat-moonpay module
This guide covers common use cases for integrating MoonPay fiat on-ramp and off-ramp functionality in your WDK application.
Basic Setup
First, install the module:
npm install @tetherto/wdk-protocol-fiat-moonpayInitializing the Module
import MoonPayProtocol from '@tetherto/wdk-protocol-fiat-moonpay';
// Initialize with a wallet account
const moonpay = new MoonPayProtocol(walletAccount, {
apiKey: 'pk_live_xxxxx',
secretKey: 'sk_live_xxxxx',
});Read more about configuration in Configuration.
Buying Cryptocurrency (On-Ramp)
Generate a widget URL for users to purchase cryptocurrency:
// Buy $100 worth of ETH
const result = await moonpay.buy({
cryptoAsset: 'eth',
fiatCurrency: 'usd',
fiatAmount: 10000n, // Amount in cents ($100.00)
});
// Open the MoonPay widget
window.open(result.buyUrl, '_blank');You can also specify the crypto amount instead:
Selling Cryptocurrency (Off-Ramp)
Generate a widget URL for users to sell cryptocurrency:
Getting Price Quotes
Get a quote before initiating a transaction:
Fetching Supported Currencies
Query which cryptocurrencies and fiat currencies are supported:
Checking Transaction Status
Retrieve details about a transaction:
Customizing the Widget
Pass configuration options to customize the MoonPay widget:
Specifying a Custom Recipient Address
By default, the module uses the wallet account's address. You can override this:
For sell operations, you can specify a refund address:
Next Steps
Configuration - Detailed configuration options
API Reference - Complete API documentation

