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:
- Register as a Saber merchant: In case you have not, get started by reaching out to our team here
- Setting up your keys:
- Keep your keys handy. Each API call requires an authentication signature. Create it using the guide Authentication: Configuring Your Keys
- To initiate the SDK create the SDK credentials.
- Create a user: A user forms the base of operations. Create your user using the Guide
- 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 parameter | Description |
---|---|
client_id | Provided by Saber |
user_id | When creating the user, the UUIDv4 will be generated for the user |
timestamp | The timestamp of the payment request (used at the time of creating the secret) |
secret | The secret generated in step 4.1 |
wallet_address | This is the on-chain wallet address to which the cryptocurrency will be withdrawn. |
fiat_amount | This 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:
Field | Description |
---|---|
crypto_symbol | This is the unique identifier of the cryptocurrency. Currently, we support USDT . |
network | This is the network on which you want to withdraw the cryptocurrency. For a list of currently supported networks, refer to this document here |
crypto_amount | This 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_method | The type of method the user would choose to pay with. For a list of currently supported methods, refer to this document here |
transaction_id | A UUID16 identifier is passed by the client. The client will receive webhooks with the same transaction_id. |
fiat_currency | This is the fiat currency the user wants to pay |
redirect_url | This 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
Environment | Link |
---|---|
Production | https://app.saber.money/onramp |
Sandbox | https://app.sandbox.saber.money/onramp |
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.
Updated 11 days ago