Skip to main content

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.

getMoonPayCurrencies

Fetches the list of crypto currencies supported by MoonPay for a given chain and network, filtered to active currencies only. Use this to build a token picker before generating a MoonPay onramp URL with getMoonPayUrl. Requires a MoonPay onramp to be enabled and configured for your environment in the Dynamic dashboard.

Usage

import { getMoonPayCurrencies } from "@dynamic-labs-sdk/client";

const currencies = await getMoonPayCurrencies({
  chain: "EVM",
  networkId: "1", // Ethereum mainnet
});

currencies.forEach((currency) => {
  console.log(currency.code, currency.name);
});

Parameters

ParameterTypeDescription
chainChainThe blockchain to fetch supported currencies for (e.g., 'EVM', 'SOL').
networkIdstring (optional)The network ID to filter currencies by (e.g., '1' for Ethereum mainnet, '137' for Polygon).
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<MoonPayCurrency[]> - A promise that resolves to an array of supported MoonPay currencies. Returns an empty array if none are available.
type MoonPayCurrency = {
  code: string; // MoonPay currency code (e.g., 'usdc', 'eth')
  name: string; // Human-readable name (e.g., 'USD Coin')
  icon: string; // URL to the currency icon
};

Examples

Build a token picker

import { useEffect, useState } from "react";
import {
  getMoonPayCurrencies,
  getMoonPayUrl,
} from "@dynamic-labs-sdk/client";

const MoonPayTokenPicker = ({ walletAddress }) => {
  const [currencies, setCurrencies] = useState([]);

  useEffect(() => {
    getMoonPayCurrencies({ chain: "EVM", networkId: "1" })
      .then(setCurrencies)
      .catch((error) => console.error("Failed to load currencies", error));
  }, []);

  const handleSelect = async (code) => {
    const url = await getMoonPayUrl({
      chain: "EVM",
      walletAddress,
      token: code,
      currency: "USD",
    });

    window.open(url, "_blank");
  };

  return (
    <ul>
      {currencies.map((currency) => (
        <li key={currency.code} onClick={() => handleSelect(currency.code)}>
          <img src={currency.icon} alt={currency.name} width={20} />
          {currency.name} ({currency.code.toUpperCase()})
        </li>
      ))}
    </ul>
  );
};

Check if a token is supported

import { getMoonPayCurrencies } from "@dynamic-labs-sdk/client";

const isTokenSupported = async (code) => {
  const currencies = await getMoonPayCurrencies({ chain: "EVM" });

  return currencies.some(
    (currency) => currency.code.toLowerCase() === code.toLowerCase()
  );
};

const canBuyUsdc = await isTokenSupported("usdc");

Errors

ErrorDescription
MoonPayCurrenciesFetchErrorThe request to fetch supported MoonPay currencies failed.

Prerequisites

  • MoonPay must be enabled and configured as an onramp provider for your environment in the Dynamic dashboard.