Overlay Mode

If you want to quickly integrate Onramp into your web app with an overlay, this is the right place to learn how to do that. This method will bring Onramp up as an overlay on top of your web app.

Getting the SDK

Option 1 - you can use npm or yarn to add our SDK to your project.

# npm
$ npm install @onramp.money/onramp-web-sdk

# yarn
$ yarn add @onramp.money/onramp-web-sdk

Option 2 - you can choose to include SDK in HTML / JS via script tag

<script type="module">
        import { OnrampWebSDK } from 'https://cdn.skypack.dev/@onramp.money/onramp-web-sdk';
        window.OnrampWebSDK = OnrampWebSDK;
</script>

Using the SDK

In order to start the widget, you need to provide some basic configuration to the constructor of our SDK.

Import the SDK - version 1.4.0 or higher

import { OnrampWebSDK } from '@onramp.money/onramp-web-sdk';

Quick Start Guide

A basic example looks like this:

For full list of parameters , click here

const onrampInstance = new OnrampWebSDK({
  appId: 1, // replace this with the appID you got during onboarding process
  walletAddress: '0x495f519017eF0368e82Af52b4B64461542a5430B', // replace with user's wallet address
  flowType: 1 // 1 -> onramp || 2 -> offramp || 3 -> Merchant checkout
  fiatType: 1 // 1 -> INR || 2 -> TRY || 3 -> AED || 4 -> MXN || 5-> VND || 6 -> NGN etc. visit Fiat Currencies page to view full list of supported fiat currencies
  paymentMethod: 1 // 1 -> Instant transafer(UPI) || 2 -> Bank transfer(IMPS/FAST)
  lang: 'vi' // for more lang values refer 
  // ... pass other configs
});

// when you are ready to show the widget, call show method
onrampInstance.show();

// to close the widget, call close method 
onrampInstance.close();

Note:

  • Supported Currencies: To view the list of all the fiat currencies supported by Onramp, click here.

  • Supported Payment Methods: To view the list of all the supported payment methods for various currencies supported by Onramp, click here.

Listening to events from SDK

// bind events to the sdk instance created above

// listens to all the events of a tx stages
onrampInstance.on('TX_EVENTS', (e) => {    
    /**
        e:{
            type : [ONRAMP_WIDGET_TX_INIT, ONRAMP_WIDGET_TX_SENDING_FAILED, ONRAMP_WIDGET_TX_PURCHASING_FAILED, ONRAMP_WIDGET_TX_FINDING_FAILED, ONRAMP_WIDGET_TX_FINDING, ONRAMP_WIDGET_TX_PURCHASING, ONRAMP_WIDGET_TX_SENDING, ONRAMP_WIDGET_TX_COMPLETED]
            data - object with tx data
          }
    **/
    console.log('onrampInstance TX_EVENTS', e);
});

// listens to all the events of a widget stages
onrampInstance.on('WIDGET_EVENTS', (e) => {
    /**
        e:{
            type : [ONRAMP_WIDGET_READY, ONRAMP_WIDGET_FAILED, ONRAMP_WIDGET_CLOSE_REQUEST_CONFIRMED],
            data - object with event data
          }
    **/
    console.log('onrampInstance WIDGET_EVENTS', e);
});

Widget Transactions Events

TX_EVENTS

ONRAMP_WIDGET_TX_INIT, 
ONRAMP_WIDGET_TX_SENDING_FAILED, 
ONRAMP_WIDGET_TX_PURCHASING_FAILED, 
ONRAMP_WIDGET_TX_FINDING_FAILED, 
ONRAMP_WIDGET_TX_FINDING, 
ONRAMP_WIDGET_TX_PURCHASING, 
ONRAMP_WIDGET_TX_SENDING, 
ONRAMP_WIDGET_TX_COMPLETED

WIDGET_EVENTS

ONRAMP_WIDGET_READY, 
ONRAMP_WIDGET_FAILED, 
ONRAMP_WIDGET_CLOSE_REQUEST_CONFIRMED
ONRAMP_WIDGET_CONTENT_COPIED

Widget Event Data

The events triggered by the SDK come with an associated data field. This provides partners with a streamlined way to track order statuses. Here's a breakdown of a sample response and its interpretation.

ONRAMP_WIDGET_TX_INIT

"data": {
    "coinRate": 90.2,
    "cryptoAmount": 1.02,
    "fiatAmount": 101,
    "paymentMethod": "UPI"
  }

ONRAMP_WIDGET_TX_FINDING

"data": {
    }

ONRAMP_WIDGET_TX_PURCHASING

"data": {
    "kycNeeded": 0
  }

ONRAMP_WIDGET_TX_SENDING

"data": {
    "actualCryptoAmount": 1.11,
    "actualPrice": 90.2,
    "gasFee": 0.09
  }

ONRAMP_WIDGET_TX_COMPLETED

"data": {
    "actualCryptoAmount": 1.11,
    "actualPrice": 90.2,
    "chainId": 3,
    "clientFee": 0,
    "coinId": 54,
    "createdAt": "2023-10-13T07:49:58.000Z",
    "expectedCryptoAmount": 1.03,
    "expectedPrice": 90.2,
    "fiatAmount": 101,
    "fiatType": 1,
    "gasFee": 0.09,
    "gatewayFee": 0,
    "kycNeeded": 0,
    "merchantRecognitionId": null,
    "onRampFee": 0.25,
    "orderId": 302342,
    "orderStatus": 4,
    "referenceId": "327624383007",
    "transactionHash": "0xc1a8aaa9c887ca8f0c3b929caa71b2337c840b353939d3b6b340948ae5d",
    "updatedAt": "2023-10-13T07:56:04.000Z",
    "walletAddress": "0x63dDcda9ABC022Ce0E179A0F6f033Ea3282807b"
  }

Note:

  • Each instance of the SDK maps directly to a single widget instance. Should you wish to close and subsequently reopen Onramp Instant, a fresh SDK initialization is required.

Last updated