WEPIN Developer Documentation
WepinBlogContact
English
English
  • Get Started
    • Introduction
  • Wepin
    • Features
    • Architecture
      • Key Generation
      • Signing
      • Key Backup
    • Workspace
      • App Registration and Key Issuance
      • Networks and Assets Addition
      • Widget Design
    • Supported blockchains
    • Account Abstraction
  • login
    • Overview
    • Social Login Auth Providers
      • Email/Password
      • Google
      • Apple
      • Discord
      • Naver
      • Facebook
      • Line
      • Kakao
    • User Interface
    • Simplified Login
    • Resource
  • Widget Integration
    • Prerequisites
    • Web: JavaScript SDK
      • Login Library
        • Installation
        • Initialization
        • Methods
      • PIN Pad Library
        • Installation
        • Initialization
        • Methods
      • Widget
        • Installation
        • Initialization
        • Methods
        • Final Review
      • Provider
        • Ethereum Provider
        • Kaia Provider
        • Solana Provider
        • Wagmi Connector
      • Wallet Adapter
        • Solana Wallet Adapter
    • Android: Java & Kotlin SDK
      • Login Library
        • Installation
        • Initialization
        • Methods
      • PIN Pad Library
        • Installation
        • Initialization
        • Methods
      • Widget Library
        • Installation
        • Initialization
        • Methods
    • iOS: Swift SDK
      • Login Library
        • Installation
        • Initialization
        • Methods
      • PIN Pad Library
        • Installation
        • Initialization
        • Methods
      • Widget Library
        • installation
        • initialization
        • Methods
    • Flutter SDK
      • Login Library
        • Installation
        • Initialization
        • Methods
      • Widget
        • Installation
        • Initialization
        • Methods
        • Final Review
      • PIN Pad Library
        • Installation
        • Initialization
        • Methods
    • React Native SDK
      • Login Library
        • Installation
        • Initialization
        • Methods
    • Unity SDK
      • Installation
      • Initialization
      • Methods
      • Final Review
    • Compose Multiplatform SDK
      • Login Library
        • Installation
        • Initialization
        • Methods
      • Widget
        • Installation
        • Initialization
        • Methods
        • Final Review
  • API
    • Overview
    • Registration
    • Login
    • Wallet
    • Token and NFT
    • Transaction
  • Deprecated
    • Web: JavaScript SDK
      • SDK
        • Installation
        • Initialization
        • Methods
        • Final Review
      • Provider
        • EVM-Compatible Networks
      • Wagmi Connector
    • Android: Java & Kotlin SDK
      • Installation
      • Initialization
      • Methods
      • Final Review
    • iOS: Swift SDK
      • Installation
      • Initialization
      • Methods
      • Final Review
    • Flutter SDK
      • Installation
      • Initialization
      • Methods
      • Final Review
    • React Native SDK
      • Installation
      • Initialization
      • Methods
      • Final Review
      • Providers
        • Ethereum Providers
  • MISC
    • Logo & Brand
Powered by GitBook
On this page
  • getStatus
  • Parameters
  • Return value
  • Example
  • openWidget
  • Parameters
  • Return Value
  • Example
  • closeWidget
  • Parameters
  • Return Value
  • Example
  • loginWithUI
  • Parameters
  • Return Value
  • Example
  • getLoginSession
  • Supported Version
  • Parameters
  • Return Value
  • Example
  • register
  • Parameters
  • Return Value
  • Example
  • registerUserEmail
  • Supported Version
  • Parameters
  • Return Value
  • Example
  • logout
  • Parameters
  • Return Value
  • Example
  • getAccounts
  • Parameters
  • Return Value
  • Example
  • getBalance
  • Parameters
  • Return Value
  • Example
  • send
  • Parameters
  • Return Value
  • Example
  • finalize
  • Return Value
  • Example

Was this helpful?

  1. Widget Integration
  2. Web: JavaScript SDK
  3. Widget

Methods

Here are the methods provided by the Wepin Widget JavaScript SDK.

getStatus

await wepinSdk.getStatus()

It returns the lifecycle state value of WepinSDK.

Parameters

  • <void>

Return value

  • WepinLifeCycle <string>

    • not_initialized: Wepin is not initialized.

    • initializing: Wepin is being initialized.

    • initialized: Wepin initialization is complete.

    • before_login: Wepin is initialized, but the user is not logged in.

    • login: The user is logged in.

    • login_before_register : The user is logged in with email but not registered with Wepin.

Example

const status = await wepinSdk.getStatus()

openWidget

await wepinSdk.openWidget()

It shows the widget window. If a user is not logged in, the widget will not open. Therefore, you must log in to Wepin before using this method. To log in to Wepin, use the loginWithUI method or the loginWepin method from the @wepin/login-js.

Parameters

  • <void>

Return Value

  • <Promise> <void>

Example

await wepinSdk.openWidget()

closeWidget

wepinSdk.closeWidget() 

It closes the widget window. Logging out is not performed even if the window is closed.

Parameters

  • <void>

Return Value

  • <void>

Example

wepinSdk.closeWidget()

loginWithUI

await wepinSdk.loginWithUI({email}?)

It returns the information of the logged-in user. If there is no logged-in user, the Wepin widget will display the login page. To perform a login without a widget, use the loginWepin() method from @wepin/login-js.

Parameters

  • email <string> optional The email address of the user logging into Wepin.

Return Value

  • Promise <IWepinUser>

    • status <string>

      Success status <'success'|'fail'>

    • userInfo <object> optional

      • userId <string>

        The user ID in Wepin

      • email <string> The email address of the logged-in user

      • provider <string>

        <'google'|'apple'|'naver'|'discord'|'email'|'external_token'>

      • use2FA <boolean>

        Whether 2FA is enabled for the user's wallet

    • userStatus: <object>

      • loginStatus <string>

        <'complete' | 'pinRequired' | 'registerRequired'> If the user's loginStatus is not 'complete', the user needs to register with Wepin.

      • pinRequired <boolean> optional

        Whether the user's PIN number is required

    • walletId <string>

      The wallet ID of the Wepin user

    • token <object> User's wepin token

      • accessToken <string> wepin accessToken

      • refreshToken <string> wepin refreshToken

Example

//without email
const userInfo = await wepinSdk.loginWithUI()
//with email
const userInfo = await wepinSdk.loginWithUI({email})
  • response

{
    "status": "success",
      "userInfo": {
        "userId": "120349034824234234",
        "email": "abc@gmail.com",
        "provider": "google",
        "use2FA": true,
      },
}

getLoginSession

await wepinSdk.getLoginSession(provToken?)

The getLoginSession method retrieves and refreshes the Firebase authentication token. If a previous token is provided, it updates the stored token before returning the latest authentication details.

Supported Version

  • Supported in version 0.0.33 and later

Parameters

  • provToken <object> optional Previous Token

    • firebaseToken <IFirebaseWepin> Firebase login information

      • provider <string> Provider for Firebase Login

      • idToken <string> Wepin Firebase idToken

      • refreshToken <string> Wepin Firebase refreshToken

    • wepinToken <IWepinToken> User's Wepin Token

      • accessToken <string> Wepin Access Token

      • refreshToken <string> Wepin Refresh Token

Return Value

  • Promise <object>

    • firebaseToken <IFirebaseWepin> Firebase login information

      • provider <string> Provider for Firebase Login

      • idToken <string> Wepin Firebase idToken

      • refreshToken <string> Wepin Firebase refreshToken

    • wepinToken <IWepinToken> User's Wepin Token

      • accessToken <string> Wepin Access Token

      • refreshToken <string> Wepin Refresh Token

Example

//without parameter. get prevToken
const prevToken = await wepinSdk.getLoginSession()
//with parameter. refresh Firebase Token.
const loginToken = await wepinSdk.getLoginSession(prevToken)
  • respnse

{
  "firebaseToken": {
    "provider": "google",
    "idToken": "eyJhbGci...",
    "refreshToken": "AMf-vBwvHUYdt5..."
  },
  "wepinToken": {
    "accessToken": "eyJhbGciOiJS...",
    "refreshToken": "eyJhbGciOiJ..."
  }
}

register

await wepinSdk.register()

It registers the user with Wepin. After registration and login, the registration page of the Wepin widget opens, and registration (wallet creation and account creation) proceeds in the Wepin service. This feature is only available when the WepinSDK's WepinLifeCycle is login_before_register. After calling the loginWepin() method from @wepin/login-js, if the loginStatus value in userStatus is not 'complete', this method should be called.

Parameters

  • <void>

Return Value

  • Promise <IWepinUser>

    • status <string>

      Success status <'success'|'fail'>

    • userInfo <object> optional

      • userId <string>

        The user ID in Wepin

      • email <string>

        The email address of the logged-in user

      • provider <string>

        <'google'|'apple'|'naver'|'discord'|'email'|'external_token'>

      • use2FA <boolean>

        Whether 2FA is enabled for the user's wallet

    • userStatus: <object>

      • loginStatus <string>

        <'complete' | 'pinRequired' | 'registerRequired'>

        If the user's loginStatus is not 'complete', the user needs to register with Wepin.

      • pinRequired <boolean> optional

        Whether the user's PIN number is required.

    • walletId <string>

      The wallet ID of the Wepin user

    • token <object> User's wepin token

      • accessToken <string> wepin accessToken

      • refreshToken <string> wepin refreshToken

Example

const userInfo = await wepinSdk.register()

registerUserEmail

await wepinSdk.registerUserEmail(param)

The registerUserEmail function registers an email for accounts from OAuth providers that do not already have an email associated with them.

Supported Version

  • Supported in version 0.0.18 and later

Parameters

  • idToken <string> id token value to be used for login

  • accessToken <string> access token value to be used for login

Return Value

  • Promise <IWepinUser>

    • status <string>

      Success status <'success'|'fail'>

    • userInfo <object> optional

      • userId <string>

        The user ID in Wepin

      • email <string>

        The email address of the logged-in user

      • provider <string>

        <'google'|'apple'|'naver'|'discord'|'email'|'external_token'>

      • use2FA <boolean>

        Whether 2FA is enabled for the user's wallet

    • userStatus: <object>

      • loginStatus <string>

        <'complete' | 'pinRequired' | 'registerRequired'>

        If the user's loginStatus is not 'complete', the user needs to register with Wepin.

      • pinRequired <boolean> optional

        Whether the user's PIN number is required.

    • walletId <string>

      The wallet ID of the Wepin user

    • token <object> User's wepin token

      • accessToken <string> wepin accessToken

      • refreshToken <string> wepin refreshToken

Example

await wepinSdk.registerUserEmail({
    provider: 'google',
    idToken: 'google-idToken',
})

logout

await wepinSdk.logout()

It logs out the Wepin user.

Parameters

  • <void>

Return Value

  • Promise <void>

Example

await wepinSdk.logout()

getAccounts

await wepinSdk.getAccounts()
or
await wepinSdk.getAccounts(options?)

It returns the account information (network and address) available in the app for the user.

This function can only be used after logging into Wepin.

If the options parameter is not provided, information on all user accounts is returned.

Parameters

  • options <object> optional

    • networks <string[]> optional It's the networks of the accounts to to be returned. The blockchain networks that can be put in networks can be found on the supported blockchain page.

    • withEoa <boolean> optional Whether to include EOA accounts if there are AA accounts.

Return Value

If the user is logged in, account information Account[] of the network is returned.

  • Promise <Account[]>

    • address <string> The address of the usre account

    • network <string> The network type of the user account

    • contract <string> optional The contract address of the token

    • isAA <boolean> optional Whether it is an AA account

Example

const result = await wepinSdk.getAccounts({
  networks: ['Ethereum'], 
  withEoa: true
})
  • response

[
  {
    "address": "0x0000001111112222223333334444445555556666",
    "network": "Ethereum",
  },
  {
    "address": "0x0000001111112222223333334444445555556666",
    "network": "Ethereum",
    "contract": "0x777777888888999999000000111111222222333333",
  },
  {
    "address": "0x4444445555556666000000111111222222333333",
    "network": "Ethereum",
    "isAA": true,
  },
]

getBalance

await wepinSdk.getBalance(accounts)
or
await wepinSdk.getBalance()

It returns the balance information of the account. This function can only be used after logging into Wepin.

If the accounts parameter is not provided, the balance of all user accounts is returned.

Parameters

  • accounts <Account[]> optional

    • network <string> The network type of the user account to query the balance

    • address <string>

      The address of the user account to query the balance

    • isAA <boolean> optional

      Whether it is an AA account

Return Value

  • Promise <AccountBalanceInfo[]>

    • network <string>

      The network type of the user account

    • address <string>

      The address of the user account

    • symbol <string>

      The network symbol

    • balance <string>

      The amount of network coins held

    • tokens <TokenBalanceInfo[]>

      • symbol <string>

        The token symbol

      • balance <string>

        The amount of tokens held

      • contract <string>

        The token contract address

Example

const result = await wepinSdk.getBalance([{
  address: '0x0000001111112222223333334444445555556666',
  network: 'Ethereum',
}])
  • response

[
    {
        "symbol": "ETH",
            "balance": "1.1",
        "tokens":[
            {
                "contract": "0x123...213",
                "symbol": "TEST",
                "balance": "10"
            },
        ]
    }
]

send

await wepinSdk.send({account, txData?})

It performs the send function using the widget and returns the ID information of the send transaction. This function can only be used after logging into Wepin.

Parameters

  • account <Account>

    The sender's account information

    • network <string>

      The network type to send

    • address <string>

      The address of the account to send

  • txData <object> optional

    • to <string>

      The address to send to

    • amount <string>

      The amount to send

Return Value

  • Promise <object>

    • txId <string>

    The TXID of the send transaction

Example

const result = await wepinSdk.send({
    account: {
        address: '0x0000001111112222223333334444445555556666',
        network: 'Ethereum',
    },
    txData: {
        to: '0x9999991111112222223333334444445555556666',
        amount: '0.1',
    }
})
  • response

{
    "txId": "0x76bafd4b700ed959999d08ab76f95d7b6ab2249c0446921c62a6336a70b84f32"
}

finalize

wepinSdk.finalize() 

It terminates the use of WepinSDK. The WepinLifeCycle changes to not_initialized.

Return Value

  • void

Example

wepinSdk.finalize()

PreviousInitializationNextFinal Review

Last updated 1 month ago

Was this helpful?

provider <LoginProviders> Provider for Firebase login. The value must be one of the supported login provider names in lowercase, such as 'google', 'naver', 'discord', 'apple', 'facebook', or 'line'. Please refer to to check the supported login providers.

Wepin Social Login Auth Provider documentation
Supported blockchains