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

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

A basic example looks like this:

const onrampInstance = new OnrampWebSDK({
  appId: 1, // replace this with the appID you got during onboarding process
  coinCode: "usdt",
  network: "erc20",
  fiatAmount: 1000
  flowType: 2 // 1 -> onramp || 2 -> offramp || 3 -> Merchant checkout
  // ... pass other configs here
});

// 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_KYC_FAILED, 
ONRAMP_WIDGET_TX_UPGRADE_KYC,
ONRAMP_WIDGET_TX_SELLING_FAILED,
ONRAMP_WIDGET_TX_FINDING_FAILED,
ONRAMP_WIDGET_TX_FINDING,
ONRAMP_WIDGET_TX_SELLING,
ONRAMP_WIDGET_TX_SENDING,
ONRAMP_WIDGET_TX_SENT,
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": 88.7,
    "cryptoAmount": 1.16,
    "fiatAmount": 100,
    "walletAddress": "0xf123456789abcdef0123456789abcdef01234567"
  }

ONRAMP_WIDGET_TX_FINDING

"data": {
    "authToken": null,
    "chainData": {
      "address": "0x55d398326f99059ff775485246999027b3197955",
      "chainType": 0
    },
    "coinId": 54,
    "coinMinSell": 100,
    "coinRate": 88.7,
    "cryptoAmount": 1.16,
    "depositAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "exchangeIdList": [1, 2],
    "feeBreakdown": {
      "onRampFeeVal": 0.258459,
      "clientFeeVal": 0,
      "gatewayFeeVal": 2.36,
      "tdsFeeVal": 1.0236
    },
    "fiatAmount": 100,
    "freezePaymentMethod": true,
    "isPoolPrice": true,
    "isTestNetwork": false,
    "memo": undefined,
    "merchantRecognitionId": null,
    "network": 1,
    "networkChainId": 56,
    "orderId": 65354,
    "paymentMethod": 2,
    "redirectURL": "",
    "selectedBank": {
      "bankId": 7,
      "bankAccount": "98765432101234",
      "ifsc": "SBI1234567",
      "details": "{\"name\": \"VIJAY KUMAR\", \"mobile\": \"9876543210\", \"bankName\": \"SBI Bank\", \"branchName\": \"MUMBAI MAIN\"}"
    },

ONRAMP_WIDGET_TX_SELLING

"data": {
    "actualFiatAmount": null,
    "actualPrice": null,
    "actualQuantity": null,
    "authToken": null,
    "chainData": {
      "address": "0x55d398326f99059ff775485246999027b3197955",
      "chainType": 0
    },
    "chainId": 1,
    "clientFee": 0,
    "coinId": 54,
    "coinMinSell": 100,
    "coinRate": 88.7,
    "cryptoAmount": 1.16,
    "depositAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "exchangeIdList": [1, 2],
    "expectedPrice": 88.7,
    "expectedQuantity": 1.16,
    "feeBreakdown": {
      "onRampFeeVal": 0.258459,
      "clientFeeVal": 0,
      "gatewayFeeVal": 2.36,
      "tdsFeeVal": 1.0236
    },
    "fiatAmount": 100,
    "fiatType": 1,
    "freezePaymentMethod": true,
    "gatewayFee": 2.36,
    "isPoolPrice": true,
    "isTestNetwork": false,
    "memo": undefined,
    "merchantRecognitionId": null,
    "network": 1,
    "networkChainId": 56,
    "onrampFee": 1,
    "orderId": 12345,
    "orderStatus": 10,
    "paymentMethod": 2,
    "redirectURL": "",
    "selectedBank": {
      "bankId": 9,
      "bankAccount": "98765432101234",
      "ifsc": "SBI1234567",
      "details": "{\"name\": \"VIJAY KUMAR\", \"mobile\": \"9876543210\", \"bankName\": \"SBI Bank\", \"branchName\": \"MUMBAI MAIN\"}"
    },
    "staleOrderId": -1,
    "tdsFee": 1,
    "transactionHash": "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
    "walletAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "walletType": 102
  }

ONRAMP_WIDGET_TX_SENDING

"data": {
    "actualFiatAmount": null,
    "actualPrice": null,
    "actualQuantity": null,
    "authToken": null,
    "chainData": {
      "address": "0x55d398326f99059ff775485246999027b3197955",
      "chainType": 0
    },
    "chainId": 1,
    "clientFee": 0,
    "coinId": 54,
    "coinMinSell": 100,
    "coinRate": 88.7,
    "cryptoAmount": 1.16,
    "depositAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "exchangeIdList": [1, 2],
    "expectedPrice": 88.7,
    "expectedQuantity": 1.16,
    "feeBreakdown": {
      "onRampFeeVal": 0.258459,
      "clientFeeVal": 0,
      "gatewayFeeVal": 2.36,
      "tdsFeeVal": 1.0236
    },
    "fiatAmount": 100,
    "fiatType": 1,
    "freezePaymentMethod": true,
    "gatewayFee": 2.36,
    "isPoolPrice": true,
    "isTestNetwork": false,
    "memo": undefined,
    "merchantRecognitionId": null,
    "network": 1,
    "networkChainId": 56,
    "onrampFee": 1,
    "orderId": 12345,
    "orderStatus": 12,
    "paymentMethod": 2,
    "redirectURL": "",
    "selectedBank": {
      "bankId": 9,
      "bankAccount": "98765432101234",
      "ifsc": "SBI1234567",
      "details": "{\"name\": \"VIJAY KUMAR\", \"mobile\": \"9876543210\", \"bankName\": \"SBI Bank\", \"branchName\": \"MUMBAI MAIN\"}"
    }

ONRAMP_WIDGET_TX_SENT

"data": {
    "actualFiatAmount": 98.75,
    "actualPrice": 88.7,
    "actualQuantity": null,
    "authToken": null,
    "chainData": {
      "address": "0x55d398326f99059ff775485246999027b3197955",
      "chainType": 0
    },
    "chainId": 1,
    "clientFee": 0,
    "coinId": 54,
    "coinMinSell": 100,
    "coinRate": 88.7,
    "cryptoAmount": 1.16,
    "depositAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "exchangeIdList": [1, 2],
    "expectedPrice": 88.7,
    "expectedQuantity": 1.16,
    "feeBreakdown": {
      "onRampFeeVal": 0.258459,
      "clientFeeVal": 0,
      "gatewayFeeVal": 2.36,
      "tdsFeeVal": 1.0236
    },
    "fiatAmount": 100,
    "fiatType": 1,
    "freezePaymentMethod": true,
    "gatewayFee": 2.36,
    "isPoolPrice": true,
    "isTestNetwork": false,
    "memo": undefined,
    "merchantRecognitionId": null,
    "network": 1,
    "networkChainId": 56,
    "onrampFee": 1,
    "orderId": 12345,
    "orderStatus": 13,
    "paymentMethod": 2,
    "redirectURL": "",
    "selectedBank": {
      "bankId": 9,
      "bankAccount": "98765432101234",
      "ifsc": "SBI1234567",
      "details": "{\"name\": \"VIJAY KUMAR\", \"mobile\": \"9876543210\", \"bankName\": \"SBI Bank\", \"branchName\": \"MUMBAI MAIN\"}"
    },
    "staleOrderId": -1,
    "tdsFee": 1,
    "transactionHash": "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
    "walletAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "walletType": 102
  }

ONRAMP_WIDGET_TX_COMPLETED

"data": {
    "actualFiatAmount": 98.75,
    "actualPrice": 88.7,
    "actualQuantity": null,
    "authToken": null,
    "chainData": {
      "address": "0x55d398326f99059ff775485246999027b3197955",
      "chainType": 0
    },
    "chainId": 1,
    "clientFee": 0,
    "coinId": 54,
    "coinMinSell": 100,
    "coinRate": 88.7,
    "cryptoAmount": 1.16,
    "depositAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "exchangeIdList": [1, 2],
    "expectedPrice": 88.7,
    "expectedQuantity": 1.16,
    "feeBreakdown": {
      "onRampFeeVal": 0.258459,
      "clientFeeVal": 0,
      "gatewayFeeVal": 2.36,
      "tdsFeeVal": 1.0236
    },
    "fiatAmount": 100,
    "fiatType": 1,
    "freezePaymentMethod": true,
    "gatewayFee": 2.36,
    "isPoolPrice": true,
    "isTestNetwork": false,
    "memo": undefined,
    "merchantRecognitionId": null,
    "network": 1,
    "networkChainId": 56,
    "onrampFee": 1,
    "orderId": 54321,
    "orderStatus": 14,
    "paymentMethod": 2,
    "redirectURL": "",
    "selectedBank": {
      "bankId": 9,
      "bankAccount": "98765432101234",
      "ifsc": "SBI1234567",
      "details": "{\"name\": \"VIJAY KUMAR\", \"mobile\": \"9876543210\", \"bankName\": \"SBI Bank\", \"branchName\": \"MUMBAI MAIN\"}"
    },
    "staleOrderId": -1,
    "tdsFee": 1,
    "transactionHash": "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
    "walletAddress": "0x0123456789abcdef0123456789abcdef01234567",
    "walletType": 102
  }

It's important to remember that one instance of the SDK corresponds to one instance of the widget - if you want to close Offramp Instant and open it again, you'll need to initialise our SDK again

Last updated