@savitar.exchange/swap-sdk
v1.0.21
Published
Savitar Swap SDK
Readme
Swap Widget
Demo: https://swap.savitar.io/widget
For direct API connection, please see https://doc.savitar.io/api/
Index
Install
NPM
npm install --save @savitar.exchange/swap-sdk
or
yarn add @savitar.exchange/swap-sdk
or
<script src="https://cdn.jsdelivr.net/npm/@savitar.exchange/swap-sdk/dist/bundle.min.js"></script>Quick Start
In embedded mode, we strongly recommend to show the widget in a minimum 390px (min-width) x 400px (min-height) element to ensure best compatibility with banks 3DSecure pages."
Initialize the client
var Swap = require('swap-sdk');
// OR
import * as Swap from 'swap-sdk';
new Swap.Widget({
type: 'modal',
lang: 'en', // default langage - string - ['en', 'fr']
}).init()Mode modal
This mode loads an overlay on the click of a button or a link with id buttonId.
new Swap.Widget({
type: 'modal',
buttonId: 'swap-button',
})
.init()Mode embed
This mode loads the widget in the DOM node of your choice parametrized with embedContainerId
new Swap.Widget({
type: 'embed',
embedContainerId: 'swap-widget',
})
.init()Configurations
List of parameters of Swap.Widget config:
new Swap.Widget({
type: 'embed',
embedContainerId: 'swap-widget',
config: {
// input parameters here
}
})
.init()For wallets
email(optional): User email -string- defaultnullemail_editable(optional): Allow user to change predefined email-bool- defaulttruecurrency(optional): Currency of the order -string- defaultnullorder_type(optional):buy|sell-string- defaultbuyamount(optional): Amount of the order -float- default25amount_currency(optional): Currency of amount -string- defaulteuramount_editable(optional): Allow user to modify amount -bool- defaulttruedelivery_address(optional): Address to send ordered coins -string- defaultnullhide_confirm(optional): Hide payment confirmation (data @events) (true|false) -bool- defaultfalseref_code(optional): Referral ID for comissions -string- defaultnullfont_family(optional): Google Font name -string- defaultnullprimary_color(optional): Primary color (text or hex) -string- defaultnullsecondary_color(optional): Secondary color (text or hex) -string- defaultnull
IOV
Buy a domain
payment_type:iov,email(optional): User email -string- defaultnullemail_editable(optional): Allow user to change predefined email -bool- defaulttruedelivery_address(optional): Owner of the domain -string- defaultnullbroker_address(optional): Register commission address -string- defaultnullhide_confirm(optional): Hide payment confirmation (data @events) (true|false) -bool- defaultfalseiov_domain(optional): Set default Starname domain -string- defaultnullref_code(optional): Referral ID for comissions -string- defaultnullfont_family(optional): Google Font name -string- defaultnullprimary_color(optional): Primary color (text or hex) -string- defaultnullsecondary_color(optional): Secondary color (text or hex) -string- defaultnull
Buy IOVs
currency:IOV-stringemail(optional): User email -string- defaultnullemail_editable(optional): Allow user to change predefined email -bool- defaulttrueamount(optional): Amount of the order -float- default25amount_currency(optional):IOVorEUR-string- defaultEURamount_editable(optional): Allow user to modify amount -bool- defaulttruedelivery_address(optional): Address to send ordered coins -string- defaultnullhide_confirm(optional): Hide payment confirmation (data @events) (true|false) -bool- defaultfalseref_code(optional): Referral ID for comissions -string- defaultnullfont_family(optional): Google Font name -string- defaultnullprimary_color(optional): Primary color (text or hex) -string- defaultnullsecondary_color(optional): Secondary color (text or hex) -string- defaultnull
Buttons
Pay button with simple configuration
Attributes
svt-currency: Currency of order -string- defaultnullsvt-email(optional): User email -string- defaultnullsvt-email-editable(optional): Allow user to change predefined email -bool- defaulttruesvt-amount(optional): Amount to order -float- default25svt-amount-editable(optional): Allow user to modify amount -boolsvt-amount-currency(optional): Currency of amount (ex:btc) -string- defaulteursvt-order-type(optional):buy|sell-string- defaultbuysvt-delivery-address(optional): Address to send ordered coins -string- defaultnullsvt-payment-type(optional): Payment type of widget (merchant/exchange/iov) -string- defaultnullsvt-hide-confirm(optional): Hide payment confirmation (data @events) (true|false) -bool- defaultfalsesvt-iov-domain(optional): Set default Starname domain -string- defaultnullsvt-ref-code(optional): Referral ID for comissions -string- defaultnullsvt-font-family(optional): Google Font name -string- defaultnullsvt-primary-color(optional): Primary color (text or hex) -string- defaultnullsvt-secondary-color(optional): Secondary color (text or hex) -string- defaultnull
Example
JS
const widget = new Swap.Widget({
payButtons: true,
payButtonsStyle: true
})
widget.init()HTML
<button type='svt-btn' svt-amount='50' svt-currency='usdt' svt-email='[email protected]' svt-order-type='buy'>Pay now !</button>
<button type='svt-btn' svt-amount='1' svt-currency='btc' svt-amount-currency='btc' />
<button type='svt-btn' svt-amount='50' svt-currency='btc' svt-delivery-address='367pVvSShqKzBZBA4eqHLwHB41g9NAphTd' />
<button type='svt-btn' svt-currency='xtz' />
<button type='svt-btn' svt-payment-type='iov' svt-email='[email protected]' svt-email-editable='false' >Buy Starname<button/>
<button type='svt-btn' svt-email='[email protected]' svt-currency='iov' svt-amount='100'/>
<button type='svt-btn' svt-order-type='sell' svt-currency='iov' svt-amount='100'/>Options
type:modalorembed-stringpayButtons:trueorfalse- Enable click events on swap buttons -boolpayButtonsStyle:trueorfalse- Enable auto styling of buttons -boolembedContainerId:swap-embed- Embed container id -stringiframeContainerClass:swap-widget-container- iFrame container class -stringbuttonId:swap-init- Modal button id -stringconfig: Widget configuration -object
Example
const opts = {
type: 'modal',
buttonId: 'swap-init',
config: {
email: '[email protected]',
email_editable: true,
currency: 'btc',
amount: 200,
amount_editable: false,
delivery_address: '1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX'
}
}Advanced
Callbacks
const widget = new Swap.Widget().init()
widget
.on('ready', () => {
// widget has loaded
})
.on('close', () => {
// user has closed widget
})
.on('success', (data) => {
// user has successfully paid
})
.on('failure', (data) => {
// payment failure
})Methods
Init modal in your script
const widget = new Swap.Widget({
type:'modal'
}).init()
widget
.openModal()About
Website: https://swap.savitar.io
