Skip to content

getOnrampBuyUrl

The getOnrampBuyUrl utility is a helper method to generate a Coinbase Onramp URL. It helps you customize the funding experience for your users. For example:

  • Selecting which assets should be available to buy/send
  • Selecting which networks crypto should be received on
  • Setting a default buy/send amount
  • Setting a redirect URL to return your users to your app after they complete the fund flow

See the Coinbase Onramp docs for detailed descriptions of all the available parameters.

Usage

code
import { getOnrampBuyUrl } from '@coinbase/onchainkit/fund';
 
const projectId = 'YOUR_CDP_PROJECT_ID';
const onrampBuyUrl = getOnrampBuyUrl({
  projectId,
  addresses: { '0x1': ['base'] },
  assets: ['USDC'],
  presetFiatAmount: 20,
  fiatCurrency: 'USD',
  redirectUrl: 'https://yourapp.com/onramp-return?param=foo',
});

Returns

string - Returns a full Coinbase Onramp URL that you can redirect your users to, or open in a popup.

Parameters

GetOnrampUrlWithProjectIdParams | GetOnrampUrlWithSessionTokenParams