Skip to main content
The Rampnow SDK provides a developer-friendly wrapper around the widget integration, with full TypeScript support, event handling, and a React hook.

Overview

The @rampnow/sdk package lets you embed Rampnow’s onramp/offramp widget into your application with just a few lines of code. It supports three integration modes and ships with TypeScript definitions out of the box.

Overlay Mode

Full-screen modal overlay — quickest setup, no container needed

Embedded Mode

Mount the widget inside any DOM element in your layout

Redirect Mode

Generate a URL to open in a new tab — ideal for native apps or email links

React Hook

First-class React support via useRampnowSdk
Try the SDK live at demo.rampnow.io.

Installation

npm install @rampnow/sdk
CDN (no bundler):
<script src="https://cdn.jsdelivr.net/npm/@rampnow/sdk/dist/rampnow-sdk.umd.js"></script>
When loaded via CDN, the SDK is available as window.RampnowSdk.

Quick Start

1

Get your API key

Obtain your public API key from the Rampnow Partner Dashboard under API Hub. Keys are prefixed with pk_live_....
2

Initialize the SDK

import { RampnowSdk, RampnowEventType } from '@rampnow/sdk'

const sdk = new RampnowSdk({
  apiKey: 'pk_live_YOUR_API_KEY',
  orderType: 'buy',
  srcCurrency: 'EUR',
  dstCurrency: 'ETH',
  dstChain: 'ethereum',
})
3

Open the widget

sdk.init()
4

Listen for events

sdk.on(RampnowEventType.ORDER_COMPLETED, (e) => {
  console.log('Order completed:', e.payload.orderUid)
})

Configuration

Pass a config object when creating a new RampnowSdk instance:
OptionTypeDefaultDescription
apiKeystringrequiredPartner public API key
widgetUrlstringhttps://app.rampnow.ioOverride the widget base URL
containerIdstringDOM element ID for embedded mode; omit for overlay
widthstring | number450Iframe width (px)
heightstring | number700Iframe height (px)
orderType'buy' | 'sell'Pre-select order direction
srcCurrencystringSource currency, e.g. 'EUR', 'USD'
srcChainstringSource chain
dstCurrencystringDestination currency, e.g. 'ETH', 'BTC'
dstChainstringDestination chain, e.g. 'ethereum', 'bitcoin'
paymentModestringPayment method, e.g. 'SEPA', 'ACH'
srcAmountstringPre-fill source amount
walletAddressstringPre-fill recipient wallet address
walletAddressTagstringWallet memo/tag (for XRP, XLM, etc.)
externalOrderIdstringYour own order ID for cross-referencing
utm_sourcestringUTM tracking
utm_mediumstringUTM tracking
utm_campaignstringUTM tracking

Integration Modes

Overlay Mode (Default)

Opens the widget as a full-screen modal overlay. No container element needed.
import { RampnowSdk } from '@rampnow/sdk'

const sdk = new RampnowSdk({
  apiKey: 'pk_live_YOUR_API_KEY',
  orderType: 'buy',
  srcCurrency: 'EUR',
  dstCurrency: 'ETH',
  dstChain: 'ethereum',
})

sdk.init() // Opens the overlay

Embedded Mode

Mount the widget inside a specific DOM element by providing a containerId.
<div id="rampnow-widget"></div>
import { RampnowSdk } from '@rampnow/sdk'

const sdk = new RampnowSdk({
  apiKey: 'pk_live_YOUR_API_KEY',
  containerId: 'rampnow-widget',
  width: 450,
  height: 700,
  orderType: 'buy',
  dstCurrency: 'ETH',
  dstChain: 'ethereum',
})

sdk.init()

Redirect Mode

Generate a widget URL without opening an iframe — useful for native apps, email links, or server-side flows.
import { RampnowSdk } from '@rampnow/sdk'

const url = RampnowSdk.createRedirectUrl({
  apiKey: 'pk_live_YOUR_API_KEY',
  orderType: 'buy',
  srcCurrency: 'EUR',
  srcAmount: '250',
  dstCurrency: 'BTC',
  dstChain: 'bitcoin',
  walletAddress: '0xYourWalletAddress',
})

window.open(url, '_blank')

React Integration

The SDK ships with a React hook for seamless integration in React applications.
React (>=18) and ReactDOM (>=18) are optional peer dependencies — only required when using the hook.
import { useRampnowSdk } from '@rampnow/sdk/react'
import { RampnowCommandType, RampnowEventType } from '@rampnow/sdk'
import { useEffect } from 'react'

function BuyCryptoButton() {
  const { init, close, send, on, isOpen } = useRampnowSdk({
    apiKey: 'pk_live_YOUR_API_KEY',
    srcCurrency: 'EUR',
    dstCurrency: 'ETH',
  })

  useEffect(() => {
    on(RampnowEventType.ORDER_COMPLETED, (e) => {
      console.log('Completed:', e.payload.orderUid)
      close()
    })
  }, [on, close])

  return <button onClick={init}>{isOpen ? 'Loading…' : 'Buy Crypto'}</button>
}

API Reference

new RampnowSdk(config)

Creates an SDK instance. Validates the apiKey and merges defaults. Does not open the widget — call .init() to display it.

sdk.init(): RampnowSdk

Opens the widget. If containerId is set, mounts the iframe in that element; otherwise creates a full-screen overlay. Returns this for chaining.

sdk.close(): void

Closes and removes the widget from the DOM.

sdk.on(eventType, callback): RampnowSdk

Subscribe to widget events. Returns this for chaining.
// Single event
sdk.on(RampnowEventType.ORDER_CREATED, callback)

// Multiple events
sdk.on([RampnowEventType.ORDER_CREATED, RampnowEventType.ORDER_COMPLETED], callback)

// All events
sdk.on('*', callback)

sdk.off(eventType, callback): RampnowSdk

Unsubscribe from events. Same forms as .on().

sdk.send(commandType, payload): RampnowSdk

Send a command to the widget iframe. Returns this for chaining. See Commands for available command types.
import { RampnowCommandType } from '@rampnow/sdk'

sdk.send(RampnowCommandType.UPDATE_PAYMENT_DETAIL, {
  transactionHash: '0xabc123...',
})

sdk.isOpen: boolean

Read-only property indicating whether the widget is currently displayed.

RampnowSdk.createRedirectUrl(config): string (static)

Builds a full widget URL from config without opening any iframe. Returns a URL string.

Events

Subscribe to events using sdk.on() with the RampnowEventType enum:
EventPayloadDescription
WIDGET_READYWidget iframe loaded and ready
WIDGET_CLOSEDWidget was closed
USER_AUTHENTICATEDUser signed in
ORDER_CREATEDorderUid, orderType, srcCurrency, srcChain, srcAmount, dstCurrency, dstChain, paymentMode, cryptoTxnInfo?, bankTxnInfo?Order successfully created
ORDER_PAYMENT_PROCESSINGorderUid, status, paymentStatusPayment is being processed
ORDER_PAYMENT_COMPLETEDorderUid, status, paymentStatusPayment received by Rampnow
ORDER_PAYMENT_FAILEDorderUid, status, paymentStatusPayment failed
ORDER_COMPLETEDorderUid, status, srcCurrency, srcChain, srcAmount, dstCurrency, dstChain, dstAmount, walletAddress, transactionHash, cryptoTxnInfo?Order fully completed, crypto sent
ORDER_FAILEDorderUid, statusOrder failed or cancelled
KYC_STARTEDUser started identity verification
KYC_SUBMITTEDUser submitted KYC documents
KYC_APPROVEDKYC approved
KYC_REJECTEDKYC rejected
ERRORmessage, code?Error occurred in the widget

CryptoTxnInfo

Available in ORDER_CREATED and ORDER_COMPLETED event payloads:
FieldTypeDescription
currencystringCrypto currency code, e.g. "USDC"
chainstringChain code, e.g. "ethereum"
amountstringAmount credited to the receiver
receiverAddressstringAddress that received the crypto
fillAmountstringFilled/settled amount (may differ from amount on partial fills)
senderAddressstringAddress that sent the crypto
transactionHashstringOn-chain transaction hash
statusstringStatus of the transaction

Example: Full Event Handling

import { RampnowSdk, RampnowEventType } from '@rampnow/sdk'

const sdk = new RampnowSdk({
  apiKey: 'pk_live_YOUR_API_KEY',
  orderType: 'buy',
  dstCurrency: 'ETH',
  dstChain: 'ethereum',
})

sdk
  .on(RampnowEventType.WIDGET_READY, () => {
    console.log('Widget is ready')
  })
  .on(RampnowEventType.ORDER_CREATED, ({ payload }) => {
    console.log('Order created:', payload.orderUid)
  })
  .on(RampnowEventType.ORDER_COMPLETED, ({ payload }) => {
    console.log('Order completed:', payload.orderUid)
    console.log('Tx hash:', payload.transactionHash)
  })
  .on(RampnowEventType.ERROR, ({ payload }) => {
    console.error('Widget error:', payload.message)
  })
  .init()

Commands

Commands are messages sent from the SDK to the widget using sdk.send(). This is the reverse direction of events.
Domain whitelisting required: For security, the widget only accepts commands from whitelisted origins. To whitelist your domain, please contact Rampnow. Commands sent from non-whitelisted origins will be silently ignored.
CommandPayloadDescription
UPDATE_PAYMENT_DETAIL{ transactionHash }Update payment detail with a crypto transaction hash

Example: Submit a transaction hash from your wallet

import { RampnowSdk, RampnowEventType, RampnowCommandType } from '@rampnow/sdk'

const sdk = new RampnowSdk({ apiKey: 'pk_live_YOUR_API_KEY' })

// After your wallet completes a crypto transfer, send the hash to the widget
sdk.send(RampnowCommandType.UPDATE_PAYMENT_DETAIL, {
  transactionHash: '0xabc123...',
})

// Listen for confirmation that the payment is being processed
sdk.on(RampnowEventType.ORDER_PAYMENT_PROCESSING, ({ payload }) => {
  console.log('Payment updated:', payload.paymentStatus)
})

When to Use the SDK

The SDK wraps the widget mode integration with a programmatic API. Use the SDK when you need:
  • Event-driven callbacks (order status, KYC updates)
  • Programmatic control (open/close the widget)
  • React integration via hooks
  • Type-safe configuration with TypeScript
Use Widget Mode directly when you only need a simple iframe or redirect.
Use the SDK for a drop-in widget experience. Use Hosted Mode when you need full control over the UI and want to build a custom flow using the REST APIs directly.

Next Steps