SDK Quickstart

Overview

Through this guide, you can initiate crypto buy using fiat through our web-hosted SDK and deposit it into the specified user's wallet.

Prerequisites

Before you can get started, ensure:

  1. Register as a Saber merchant: In case you have not, get started by reaching out to our team here
  2. Setting up your keys:
    1. Keep your keys handy. Each API call requires an authentication signature. Create it using the guide Authentication: Configuring Your Keys
    2. To initiate the SDK create the SDK credentials.
  3. Create a user: A user forms the base of operations. Create your user using the Guide
  4. Configure your webhooks: Saber sends a webhook for various important milestones in the flow. Set up your webhooks using the guide Webhook Configuration and IP

Implementation

Step 1: Ensure your keys have been created

  • Keep your keys handy. Each API call requires an authentication signature.
  • To initiate the SDK create the SDK credentials.

Step 2: Create your user

Create a user for whom you would like to onramp.

Step 3: KYC information of the user

There are two methods of KYC for the user:

  • The user performs KYC on the Saber SDK [proceed with this for an easy integration]
  • You share the KYC details of the user with Saber through our KYC Sharing APIs. Read more KYC Sharing

Step 4: Initiate a payment

📘

How to show price quotes to the user?

In order to show the prices to your users, use our fetch quote API. Read more at Fetching Buy Price

Step 4.1: Generate a secret key for the user and the onramp payment

For each user, a unique secrete needs to be generated

// Variables (these should be securely stored and handled)
var clientId = 'YOUR_CLIENT_ID'; // Replace with your actual client ID
var clientSecret = 'YOUR_CLIENT_SECRET'; // Replace with your actual client secret
var user_id = 'USER_ID'; // Replace with the user's ID received when creating the user in Step 2

// Step 1: Generate timestamp
var timestamp = Math.floor(Date.now() / 1000).toString();

// Step 2: Create the signature string
var sigString = clientId + timestamp + "sdk" + user_id;

// Step 3: Generate the HMAC-SHA256 signature
var secret = CryptoJS.HmacSHA256(sigString, clientSecret).toString().toUpperCase();

// The 'secret' can now be used to authenticate the SDK request 

Step 4.2: Generate redirect URL

Once the secret is created for the user, the following query parameters are required to be passed along in the base URL to create the link:

Query parameterDescription
client_idProvided by Saber
user_idWhen creating the user, the UUIDv4 will be generated for the user
timestampThe timestamp of the payment request (used at the time of creating the secret)
secretThe secret generated in step 4.1
wallet_addressThis is the on-chain wallet address to which the cryptocurrency will be withdrawn.
fiat_amountThis is the amount denoted in fiat currency

In addition to the above, the following can be passed as optional parameters. They allow you to set specific options as per your preferences:

FieldDescription
crypto_symbolThis is the unique identifier of the cryptocurrency. Currently, we support USDT.
networkThis is the network on which you want to withdraw the cryptocurrency. For a list of currently supported networks, refer to this document here
crypto_amountThis is the amount denoted in the native coin/token. Either crypto_amount or fiat_amount can be passed; if both are provided, fiat_amount takes precedence.
payment_methodThe type of method the user would choose to pay with. For a list of currently supported methods, refer to this document here
transaction_idA UUID16 identifier is passed by the client. The client will receive webhooks with the same transaction_id.
fiat_currencyThis is the fiat currency the user wants to pay
redirect_urlThis is the URL to which the user will be redirected after a successful transaction. This parameter is applicable only in hosted mode.

📘

What happens if the optional parameters are not specified?

If the optional parameters are not passed in the URL, the user is prompted to select/enter the relevant options in the SDK.

It is however recommended to pass the parameters upfront to avoid unwanted customization on the user side.

The Base URL

Example of a full link

https://app.sandbox.saber.money/onramp?client_id=d951b040-ecb0-432b-ae3c-2ae7d2d19987&user_id=d951b040-ecb0-432b-ae3c-2ae7d2d1998×tamp=1687276964&secret=CE1B5BD087BA408C2AFF01B00595007858DF496D3468CE3307CB1A7966DDC265

📘

Does the URL expire?

The URL validity is 10 minutes from the creation of the secret

Step 5: Redirect your user to the link

Once the URL is generated, redirect your user to the link, and the user will see the screen below

Once the transaction is complete, it will show up in the transaction tab in the Saber dashboard

Step 6: Wait for a success callback

As soon as the transaction is complete, we will send a webhook to your configured endpoint.

{
  "payment_method": "upi_transfer",
  "source_id": null,
  "tag": null,
  "exchange_rate": "84.99000000",
  "failure_code": null,
  "fiat_amount": "2299.00000000",
  "created_at": 1694714157000,
  "id": "xxxxxx",
  "bank_transaction_id": "xxxxxx",
  "fiat_symbol": "INR",
  "failure_desc": null,
  "crypto_symbol": "USDT",
  "network": "MATIC",
  "crypto_wallet_address": "0xXXXXXXXXXXXXX",
  "crypto_amount": "27.05000000",
  "status": "COMPLETED",
  "event": "CRYPTO_BUY",
  "user_id": "xxxxxx",
  "txn_hash": "0xXXXXXXXXXXXXX"
}

Once this webhook is received, it will be visible on the transaction tab on the Saber dashboard.