Skip to main content

JavaScript SDK

The @nowramp/sdk package provides the RampApi client for fetching quotes, creating checkouts, and tracking transactions across multiple payment gateways.

Installation

npm install @nowramp/sdk
# or
yarn add @nowramp/sdk
# or
pnpm add @nowramp/sdk

Quick Start

import { RampApi } from '@nowramp/sdk';

const api = new RampApi({ projectId: 'your_project_id' });

// 1. Get supported currencies and payment methods
const supported = await api.getSupported();

// 2. Get ranked quotes from all gateways
const quotes = await api.getQuotes({
  fiatCurrency: 'USD',
  fiatAmount: '100',
  cryptoCurrency: 'ETH',
  network: 'ethereum'
});

// 3. Create checkout with the best quote's gateway
const intent = await api.createCheckoutIntent({
  gateway: quotes.bestQuote.gatewayId,
  fiatCurrency: 'USD',
  fiatAmount: '100',
  cryptoCurrency: 'ETH',
  network: 'ethereum',
  walletAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f1bD21'
});

// 4. Redirect user to the gateway's checkout
window.location.href = intent.checkout.url;

RampApi Class

Constructor

new RampApi(config: RampApiConfig)

Configuration

interface RampApiConfig {
  projectId: string;       // Your project ID (required)
  apiKey?: string;         // Optional pk_ key for higher rate limits
  apiUrl?: string;         // Default: https://api.nowramp.com
}

Methods

getSupported(params?)

Get supported configuration (gateways, currencies, payment methods) across all enabled providers.
const config = await api.getSupported({ orderType: 'buy', country: 'US' });

console.log(config.gateways);       // Available payment gateways
console.log(config.fiats);          // Supported fiat currencies with min/max
console.log(config.cryptos);        // Supported cryptocurrencies with networks
console.log(config.paymentMethods); // Available payment methods
console.log(config.defaultGateway); // Project's default gateway
Parameters:
ParameterTypeDescription
orderType'buy' | 'sell'Filter by order type (default: 'buy')
countrystringISO 2-letter country code (auto-detected from IP if omitted)

getQuotes(params)

Get quotes from all enabled gateways, ranked by best rate.
const result = await api.getQuotes({
  fiatCurrency: 'USD',
  fiatAmount: '100',
  cryptoCurrency: 'ETH',
  network: 'ethereum',
  paymentMethodId: 'debit-credit-card', // optional
  country: 'US'                         // optional
});

console.log(result.bestQuote);             // Best exchange rate
console.log(result.fastestQuote);          // Shortest processing time
console.log(result.cheapestFees);          // Lowest total fees
console.log(result.quotes);               // All quotes, ranked
console.log(result.unavailableGateways);  // Gateways that couldn't quote
Parameters:
ParameterTypeRequiredDescription
fiatCurrencystringYesFiat currency code (e.g., 'USD')
cryptoCurrencystringYesCrypto currency code (e.g., 'ETH')
networkstringYesNetwork ID (e.g., 'ethereum')
fiatAmountstringOne requiredFiat amount (for buy orders)
cryptoAmountstringOne requiredCrypto amount (for sell orders)
orderTypestringNo'buy' or 'sell' (default: 'buy')
paymentMethodIdstringNoFilter by payment method
countrystringNoISO 2-letter country code

createCheckoutIntent(params)

Create a checkout with a specific gateway. Returns a checkout URL for iframe or redirect.
const intent = await api.createCheckoutIntent({
  gateway: 'gateway_id',
  fiatCurrency: 'USD',
  fiatAmount: '100',
  cryptoCurrency: 'ETH',
  network: 'ethereum',
  walletAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f1bD21',
  externalCustomerId: 'user_123',
  email: '[email protected]',
  redirectUrl: 'https://myapp.com/complete'
});

console.log(intent.orderId);            // Order ID for tracking
console.log(intent.checkout.method);     // 'iframe' | 'redirect' | 'widget'
console.log(intent.checkout.url);        // Checkout URL
Parameters:
ParameterTypeRequiredDescription
gatewaystringYesGateway ID from supported config
fiatCurrencystringYesFiat currency code
cryptoCurrencystringYesCrypto currency code
networkstringYesNetwork ID
fiatAmountstringOne requiredFiat amount
cryptoAmountstringOne requiredCrypto amount
walletAddressstringYes (buy)Destination wallet address
externalCustomerIdstringNoYour user ID
emailstringNoCustomer email
redirectUrlstringNoURL after checkout
metadataobjectNoKey-value metadata

getTransaction(transactionId)

Get transaction status, synced with the gateway’s latest data.
const tx = await api.getTransaction('order-uuid-here');

console.log(tx.status);            // 'pending' | 'processing' | 'completed' | 'failed' | ...
console.log(tx.cryptoAmount);      // Crypto amount received
console.log(tx.transactionHash);   // Blockchain TX hash (if available)

validateAddress(params)

Validate a wallet address format.
const result = await api.validateAddress({
  address: '0x742d35Cc6634C0532925a3b844Bc9e7595f1bD21',
  network: 'ethereum'
});

console.log(result.isValid);       // true
console.log(result.chainType);     // 'evm'

getSupportedNetworks()

Get supported networks for address validation.
const networks = await api.getSupportedNetworks();
// [{ id: 'ethereum', name: 'Ethereum', chainType: 'evm' }, ...]

Standalone Functions

Common API functions are also exported as standalone functions for minimal setup:
import {
  getSupported,
  getQuotes,
  createCheckoutIntent,
  getTransaction,
  validateAddress,
  getSupportedNetworks
} from '@nowramp/sdk';

const config = await getSupported(
  { projectId: 'your_project_id' }
);

const quotes = await getQuotes(
  { projectId: 'your_project_id' },
  { fiatCurrency: 'USD', fiatAmount: '100', cryptoCurrency: 'ETH', network: 'ethereum' }
);

const intent = await createCheckoutIntent(
  { projectId: 'your_project_id' },
  {
    gateway: quotes.bestQuote.gatewayId,
    fiatCurrency: 'USD',
    fiatAmount: '100',
    cryptoCurrency: 'ETH',
    network: 'ethereum',
    walletAddress: '0x...'
  }
);

const tx = await getTransaction(
  { apiUrl: 'https://api.nowramp.com' },
  intent.orderId
);

TypeScript Support

The SDK includes full TypeScript definitions:
import type {
  RampApi,
  RampApiConfig,
  FlowType,
  QuoteData,
  CheckoutIntent,
  Transaction
} from '@nowramp/sdk';

UMD Build

For non-bundled usage via CDN:
<script src="https://unpkg.com/@nowramp/sdk/dist/index.umd.js"></script>
<script>
  const api = new NowRamp.RampApi({
    projectId: 'your_project_id'
  });

  api.getQuotes({
    fiatCurrency: 'USD',
    fiatAmount: '100',
    cryptoCurrency: 'ETH',
    network: 'ethereum'
  }).then(quotes => {
    console.log('Best rate:', quotes.bestQuote);
  });
</script>

Browser Support

BrowserVersion
Chrome80+
Firefox75+
Safari13+
Edge80+

Bundle Size

BuildSize
ESM (minified)~15KB
UMD (minified)~18KB
Gzipped~5KB

Legacy Methods (Deprecated)

The methods below are deprecated and will be removed in a future release. They query a single payment provider instead of comparing across all gateways. Use getQuotes() and getSupported() instead.

getRate(params) — deprecated

Get a conversion rate from a single provider. Returns one rate instead of comparing across gateways.
// Deprecated — use getQuotes() instead
const rate = await api.getRate({
  from: 'USD',
  to: 'ETH',
  amount: 100,
  flowType: 'buy' // optional, default: 'buy'
});

console.log(rate.rate);                // Exchange rate
console.log(rate.destinationAmount);   // Crypto amount after fees
console.log(rate.fees.totalFee);       // Total fee
console.log(rate.provider);            // Single provider name
Parameters:
ParameterTypeRequiredDescription
fromstringYesSource currency code (e.g., 'USD')
tostringYesDestination currency code (e.g., 'ETH')
amountnumberYesAmount in source currency
flowType'buy' | 'sell'NoOrder type (default: 'buy')
Returns: RateResult
interface RateResult {
  rate: number;
  sourceAmount: number;
  sourceCurrency: string;
  destinationAmount: number;
  destinationCurrency: string;
  fees: {
    processingFee: number;
    processingFeePercent: number;
    networkFee: number;
    totalFee: number;
  };
  provider: string;
  expiresAt?: string;
}
Migration: Replace getRate() with getQuotes() to compare rates across all gateways:
// Before (single provider)
const rate = await api.getRate({ from: 'USD', to: 'ETH', amount: 100 });

// After (all providers, ranked)
const { bestQuote, quotes } = await api.getQuotes({
  fiatCurrency: 'USD',
  cryptoCurrency: 'ETH',
  network: 'ethereum',
  fiatAmount: '100'
});

getCurrencies() — deprecated

Get available currencies from a single configured provider.
// Deprecated — use getSupported() instead
const currencies = await api.getCurrencies();

console.log(currencies.fiat);        // Fiat currencies
console.log(currencies.crypto);      // Crypto currencies
console.log(currencies.provider);    // Single provider name
Migration: Replace getCurrencies() with getSupported() to get currencies, payment methods, and gateways across all providers:
// Before (single provider)
const currencies = await api.getCurrencies();

// After (all providers, with payment methods and gateways)
const supported = await api.getSupported({ orderType: 'buy' });
console.log(supported.fiats);          // All fiat currencies across gateways
console.log(supported.cryptos);        // All crypto currencies with networks
console.log(supported.paymentMethods); // Available payment methods
console.log(supported.gateways);       // Available gateways

Standalone legacy functions

The legacy methods are also available as standalone functions:
import { getRate, getCurrencies } from '@nowramp/sdk';

// Deprecated — use getQuotes() and getSupported() instead
const rate = await getRate({ projectId: 'your_project_id' }, { from: 'USD', to: 'ETH', amount: 100 });
const currencies = await getCurrencies({ projectId: 'your_project_id' });

Next Steps