Documentation Index
Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
getMoonPayUrl
Returns a signed MoonPay URL for funding a wallet with a fiat-to-crypto purchase. Open the returned URL in a new tab or popup to let the user complete the purchase on MoonPay’s hosted widget. The URL is generated through Dynamic’s onramp API and is pre-signed for your environment, so you don’t need to handle MoonPay credentials directly. Requires a MoonPay onramp to be enabled and configured for your environment in the Dynamic dashboard.Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
chain | Chain | The blockchain to fund (e.g., 'EVM', 'SOL'). |
walletAddress | string | The wallet address that will receive the purchased crypto. |
token | string (optional) | Token symbol or MoonPay currency code to lock in the widget (e.g., 'USDC', 'usdc_polygon'). |
currency | string (optional) | ISO 4217 fiat currency code used as the quote currency (e.g., 'USD', 'EUR'). |
tokenAmount | number (optional) | Pre-filled fiat amount in the quote currency. This is the amount the user spends in fiat, not the crypto amount they receive (maps to MoonPay’s quoteCurrencyAmount). |
networkId | string (optional) | The network ID to scope the purchase to (e.g., '1' for Ethereum mainnet, '137' for Polygon). |
merchantName | string (optional) | Your app or merchant name shown to the user in the widget. |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
Promise<string> - A promise that resolves to the signed MoonPay URL.
Examples
Open in a popup window
Pre-fill a purchase amount
Lock the widget to a specific token and pre-fill the fiat amount the user will spend:Handle errors
Errors
| Error | Description |
|---|---|
MoonPayProviderNotAvailableError | MoonPay is not available for the requested environment, chain, or token, or no onramp URL was returned. |
MoonPayInvalidUrlError | The onramp API returned a URL that failed host/scheme validation. The URL is verified to use https: and a moonpay.com host before it is returned. |
Prerequisites
- MoonPay must be enabled and configured as an onramp provider for your environment in the Dynamic dashboard.
- The requested
chainandtokenmust be supported by MoonPay. UsegetMoonPayCurrenciesto discover supported tokens.
Related functions
- getMoonPayCurrencies - List crypto currencies supported by MoonPay for a chain
- getCoinbaseBuyUrl - Get a Coinbase onramp buy URL
- createCryptoDotComPayment - Create a Crypto.com payment