Skip to main content

getCoinbaseBuyUrl

Gets a Coinbase buy URL for initiating a fiat-to-crypto purchase flow. This is the simplest way to integrate Coinbase onramp - the URL opens in a new tab or popup window where the user completes the purchase on Coinbase’s site. Use this when you want a simple redirect-based flow. For an embedded iframe experience with real-time event tracking, use createCoinbaseOnrampOrder instead.

Usage

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

const { url } = await getCoinbaseBuyUrl({
  destinationAddress: "0x1234...",
  defaultAsset: "ETH",
  networks: ["ethereum"],
  fiatCurrency: "USD",
  presetCryptoAmount: "0.1",
});

// Open in a new window
window.open(url, "_blank", "width=500,height=600");

Parameters

ParameterTypeDescription
destinationAddressstringThe wallet address to receive the purchased crypto.
defaultAssetstringThe default asset to purchase (e.g., ETH, USDC).
networksstring[]The networks to show (e.g., ["ethereum", "polygon"]).
fiatCurrencystringThe fiat currency for payment (e.g., USD, EUR).
presetCryptoAmountstring (optional)Pre-filled crypto amount to purchase.
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<{ url: string }> - A promise that resolves to an object containing the Coinbase buy URL.

Examples

Open in popup window

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

const BuyWithCoinbaseButton = ({ walletAddress }) => {
  const handleBuy = async () => {
    const { url } = await getCoinbaseBuyUrl({
      destinationAddress: walletAddress,
      defaultAsset: "ETH",
      networks: ["ethereum"],
      fiatCurrency: "USD",
      presetCryptoAmount: "0.1",
    });

    // Open Coinbase in a popup window
    window.open(url, "_blank", "width=500,height=600");
  };

  return <button onClick={handleBuy}>Buy with Coinbase</button>;
};

Full page redirect

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

const redirectToCoinbase = async (walletAddress) => {
  const { url } = await getCoinbaseBuyUrl({
    destinationAddress: walletAddress,
    defaultAsset: "USDC",
    networks: ["polygon"],
    fiatCurrency: "USD",
  });

  // Redirect the entire page to Coinbase
  window.location.href = url;
};

When to use getCoinbaseBuyUrl vs createCoinbaseOnrampOrder

FeaturegetCoinbaseBuyUrlcreateCoinbaseOnrampOrder
User experienceOpens new tab/popupEmbedded iframe in your app
Event trackingNoYes, via addCoinbaseOnrampOrderEventListener
User verificationNot requiredEmail and phone verification required
Implementation complexitySimpleMore complex