Leap Near SDK
  • Leap Near SDK
    • Introduction
    • Installation
    • Social Login and Wallet Creation
      • Desktop
      • Mobile
    • Fetch Token Balances
    • Fetch NFTs
    • Mint NFTs
      • Desktop
      • Mobile
    • Examples
      • React
      • React Native
    • FAQ
      • Webpack 5 issue
Powered by GitBook
On this page
  • Init
  • LeapNearSdk.auth
  • auth.Connect
  • auth.getUser
  • auth.logout
  1. Leap Near SDK
  2. Social Login and Wallet Creation

Desktop

PreviousSocial Login and Wallet CreationNextMobile

Last updated 2 years ago

Init

The init method is been used to initialize the SDK with the specified auth service and auth config. This returns the SDK instance with auth object to be used.

Leap Near SDK supports two types of authentication services. You can choose which one you want to go ahead with.

  1. Web3Auth -

  2. Ramper -

You need to pass an API_TOKEN to auth config in order to get data from backend. Kindly send an email to admin@leapwallet.io for generating the API_TOKEN for you

1. Login via Web3Auth

Using Web3Auth, Leap Near SDK is supporting Google for now, where the user is expected to provide the following config.

Kindly send an email to admin@leapwallet.io for whitelisting your domain from our side for security reasons, by default localhost:3000 would be whitelisted.

import { LeapNearSdk } from '@leapwallet/leap-near-sdk'

const sdk = await LeapNearSdk.init({ 
    auth_service: 'web3auth',
    authConfig: { apiToken: YOUR_API_TOKEN }
})

2. Login via Ramper

For using the Ramper the params are specified below while initializing the SDK.

import { LeapNearSdk } from '@leapwallet/leap-near-sdk'

const sdk = await LeapNearSdk.init({ 
    auth_service: 'ramper',
    authConfig: { appName: 'Leap near board',  theme: 'dark',  apiToken: YOUR_API_TOKEN}  
})

LeapNearSdk.auth

Once the SDK is been initialized with the expected auth provider, we would be getting the SDK object with auth property.

The sdk.auth contains the methods to

  1. Connect to the social login,

  2. Getting the user information

  3. Logging out the user

auth.Connect

await sdk?.auth?.connect()

In the case of Web3Auth

auth.connect() would show the google login screen for the user to select the account for which the wallet needs to be created. If the user comes the first time it will create the wallet in the near chain and if it is a returning user it will get the public address of the user.

In the case of Ramper

auth.connect() would show the popup modal for doing the social login for the user. If the user comes the first time it will create the wallet in the near chain and if it is a returning user it will get the public address of the user.

auth.getUser

const signedData =  await sdk?.auth?.getUser();

auth.getUser() would provide the user information like,

name - The name of the user in his social profile

loginProvider - The social login which the user used - google, facebook, reddit, jwt, etc.

address - The wallet's public address

wallets - Wallets associated with the user's social profile (only would be available for Ramper for now)

Sample Response
{
    "email": "support@leapwallet.io",
    "loginProvider": "google.com",
    "address": "324187b98b3973e36670d164520a5880fd53c62f0423e096cf1daca6b2471d2c",
    "wallets": {
        "near": {
            "version": 4,
            "walletId": "near-4_324187b98b3973e36670d164520a5880fd53c62f0423e096cf1daca6b2471d2c",
            "creationDate": 1670589544159,
            "publicKey": "324187b98b3973e36670d164520a5880fd53c62f0423e096cf1daca6b2471d2c",
            "blockchain": "near"
        }
    }
}

auth.logout

const signedData =  await sdk?.auth?.logout();

auth.logout() will log the user out of the session.

https://web3auth.io/
https://www.ramper.xyz/