@uniblock/onramper v0.0.1-5
Uniblock SDK Onramper
Steps to call functions from Onramper Docs:
First we call to
getGateways
to get a list of the cryptos, currencies and payment methods available.Once we have selected the fromCurrency, the toCurrency, the paymentMethod and the amount we want to buy, we make a call to
getRate
to know which onramps are availables for that combination.If the amount is enough to give us at least one onramp available, we can start the process of buying crypto. If not, we should make another call fixing one of the errors described in the attribute error.
Now that we have selected the onramp we want to use, we should check the attribute
nextStep
to know which is the first step to start with the purchase flow. Once we complete a step, we will get a new step on the response. We will keep executing steps until the flow is finished. To execute step, please callexecuteStep
with given url.
How to Install Package
Run
yarn run compile
ornpm run compile
in uniblock-sdk-onramper (you should also do this each time you've made changes to this package)Run
yarn link
ornpm link
in uniblock-sdk-onramperIn the project you want to use this package, run
yarn link "@uniblock/onramper"
ornpm link "@uniblock/onramper"
Quickstart
In order to access the SDK's functionalities, you must first create an instance of the Onramper class. This is done using the initializeOnramper function. You may then use the returned object to call desired methods. When calling the initializeOnramper function, you must ensure to pass in the Uniblock and Onramper API keys.
import { initializeOnramper } from '@uniblock/onramper';
// getting instance of the Onramper class
const onramper = await initializeOnramper(uniblockApiKey, apiKey);
getGateways
Call getGateways() to get a list of the cryptos, currencies and payment methods available.
Params
parameter | type | description |
---|---|---|
searchParams | getGatewaySearchParams | Contains optional search parameters. |
Optional search parameters:
| search parameter | type | description |
| -------------- | ---------------------- | ------------------------------------ |
| country?
| string | Defines which onramps are available. By default, country is automatically detected by the API using client's IP but can be overwritten by providing its ISO 3166 alpha-2 code (eg: 'us', 'gb'...). |
| includeIcons?
| boolean | If true, includes icons of the cryptos, currencies and payment methods in the response. |
Example
type getGatewaysSearchParams = {
country?: string,
includeIcons?: boolean,
};
const searchParams: getGatewaysSearchParams = {
country: 'ca',
includeIcons: false,
};
await onramper.getGateways(searchParams);
// For onramper, check initializing step
getRate
Call getRate() to get a list of accessible onramps.
Params
parameter | type | description |
---|---|---|
fromCurrency | string | The Currency to pay with. Currently, only fiat currencies are allowed. |
toCurrency | string | The Currency to buy. Currently, only cryptocurrencies are allowed. |
paymentMethod | string | The Payment method to use. |
amount | number | The amount of currency to buy, by default, amount of fromCurrency. |
searchParams | getRateSearchParams | Contains optional search parameters |
Optional search parameters:
search parameter | type | description |
---|---|---|
country? | string | Defines which onramps are available. By default, country is automatically detected by the API using client's IP but can be overwriten by providing its ISO 3166 alpha-2 code (eg: 'us', 'gb'...). |
includeIcons? | boolean | If true, includes icons of the cryptos, currencies and payment methods in the response. |
amountInCrypto? | number | If true, the amount specified in {amount} represents the amount of crypto user wants to buy. |
accepted paymentMethod values:
creditCard, bankTransfer, applePay, googlePay, paynow, fps, alipay-hk, prompt-pay, instapay, upi, gojek-id, viettel-pay, duit-now, ideal, bancontact, giropay, sofort, sepaBankTransfer
Example
const fromCurrency: string = 'EUR';
const toCurrency: string = 'BTC';
const paymentMethod: string = 'creditCard';
const amount: number = 100;
type getRateSearchParams = {
country?: string,
includeIcons?: boolean,
amountInCrypto?: number,
};
const searchParams: getGatewaysSearchParams = {
country: 'ca',
includeIcons: false,
};
await onramper.getGateways(
fromCurrency,
toCurrency,
paymentMethod,
amount,
searchParams,
);
// For onramper, check initializing step
executeStep
Call executeStep() to get a list of accessable onramps.
Example
const nextStepUrl: string =
'https://onramper.tech/transaction/Moonpay/redirect/WyJXeUo3WENKcFpGd2lPbHdpTkhoTE9YSk5NVTFyV21GTlpFcGtSMUZLYmpaTlFTMHRYQ0lzWENKaGJXOTFiblJjSWpveU1EQXNYQ0pwYmtOMWNuSmxibU41WENJNlhDSkRRVVJjSWl4Y0ltOTFkRU4xY25KbGJtTjVYQ0k2WENKQ1ZFTmNJaXhjSW5CaGVXMWxiblJOWlhSb2IyUmNJanBjSW1OeVpXUnBkRU5oY21SY0lpeGNJa0ZRU1V0bGVWd2lPbHdpY0d0ZmRHVnpkRjl4TmpoRk5HNUVRamd4WTJaUk9ISllNRXc1VEdobE9HVkVlSHBTWVc0MGRWRnZWamhrTTJWR01IRkZNRndpTEZ3aVpYaHdaV04wWldSU1pXTmxhWFpsWkVOeWVYQjBiMXdpT2pJd01DeGNJbkJoY25SdVpYSkdaV1ZjSWpvd0xGd2liMjV5WVcxd1pYSkdaV1ZjSWpveExGd2lZM0o1Y0hSdlFXUmtjbVZ6YzF3aU9tNTFiR3dzWENKamNubHdkRzlCWkdSeVpYTnpWR0ZuWENJNmJuVnNiSDBpWFE9PSIsIjE0MjQ3MGE1OGVhNzhlZGRkYWFiY2VkYzI4ZTA0MDQyYmViNjI5ODcwNjA1ZDIzY2ZjOWY4Y2Y3YWViMjUyOTciXQ==?country=ca';
const method: string = 'POST';
// In most cases, method is POST, sometimes it is PUT.
const body: object = {};
await onramper.getGateways(nextStepUrl, method, body);
// For onramper, check initializing step