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

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,
      },
}

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

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

  • 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 Wepin Social Login Auth Provider documentation to check the supported login providers.

  • 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

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()

Last updated