🔬
Singularity Developer Documentation
  • 👋Hi! Welcome to Singularity
  • Overview
    • 💡What we do
    • ✨Our Products
  • TECHNICAL PAPERS
    • ✨White papers
  • Integration First Steps
    • 🛠️Account Setup
  • Wallet Integration Guide
    • SDK setup and initialization
    • User Sign-in and registration
    • Wallet APIs and Callbacks
  • Payments Integration Guide
    • SDK setup and initialization
    • User Sign-in and registration
    • Buy Tokens
    • NFT Checkout
  • Legal
    • Terms of Service
    • Privacy Policy
Powered by GitBook
On this page
  • Sample Implementation
  • See Singularity in action in our web Demo Apps
  1. Wallet Integration Guide

SDK setup and initialization

PreviousAccount SetupNextUser Sign-in and registration

Last updated 10 months ago

Step 1: Setup your Account

Register with us and get your Key and Secret by following the steps mentioned in . Also whitelist your domain name with us. While using our services, use these Key and Secret while calling the APIs.

Step 2: Import the SDK

The first step is to import the Singularity SDK into your app. The SDK allows your app to use the Singularity Drawer, open and close the drawer and let users interact with it as you deem fit using the APIs mentioned in the sections below. The Singularity Drawer automatically switches between Wallet and Payments based on the APIs you use.

Add the following self-calling function snippet and supporting snippet in your application's HTML body:

(function (w, d, s, o, f, js, fjs, e) {
    w[o] =
    w[o] ||
    function () {
        (w[o].q = w[o].q || []).push(arguments);
    };
    (js = d.createElement(s)), (fjs = d.getElementsByTagName(s)[0]);
    js.id = o;
    js.src = f;
    js.async = 1;
    fjs.parentNode.insertBefore(js, fjs);
    w.SingularityEnv = e;
})(
    window,
    document,
    "script",
    "Singularity",
    "https://unpkg.com/singularity-client-script@latest/index.js", '', '',
    'production'
);

Alternatively, you can import the library from NPM and call the initializeSingularity() function

npm install singularity-init
import { initializeSingularity } from 'singularity-init';
initializeSingularity(window, document,'latest','production',apiKey,async () => {
    // Init success callback. All singularity methods are to be called after 
    // init success
})

Step 3: Initialize the Singularity SDK

Now you must initialize the Singularity SDK. For this, you need the Key which you get during account setup. We notice that on some browsers, there can be a race condition if the initialization is done before checking that the SDK has been mounted. Hence please follow either of the following 2 methods to first check if the mount is successful, before initializing.

Similarly, please use the callbackFn feature during initialization to confirm that initialization has completed before calling any other Singularity APIs.

Method 1:

Add an event listener as follows:

const bodyElem = document.getElementsByTagName('body')[0];

bodyElem.addEventListener('Singularity-mounted', (e) => {
	// Singularity is mounted
	Singularity.init(API_KEY, callbackFn); //callbackFn is optional but recommended
});

Alternate Method 2:

When mounted successfully, the below object key can be referred:

window.Singularity.isMounted //returns true if mounted, else false

Once Injection is done:

Singularity.init(API_KEY, callbackFn); //callbackFn is optional but recommended

Sample Implementation

See Singularity in action in our web Demo Apps

Visit to check out our web Demo App using the Singularity integration

Account Setup
https://github.com/coinbrix/demo-app
/
https://demo.s9y.gg?key=2