Methods

The following shows the methods provided by the Wepin React SDK.

openWidget

_wepin.openWidget();

The openWidget method shows the widget window.

Returned Value

  • <void>

closeWidget

_wepin.closeWidget();

The closeWidget method closes the widget window.

Returned value

  • <void>

getAccounts

_wepin.getAccounts();

The getAccounts method returns user accounts of the networks available in the app. getAccounts is a method available after widget login.

Parameters

  • networks: Array of string It is the network of the address you want to receive. If no network is specified, all addresses available in the app are returned. The names of blockchain networks that can be put into networks can be found on the following page.

Returned Value

  • Promise <Array>

    • If a user is logged in, it returns a Promise object resolved with array of account of networks.

      • Type of account is assigned at @wepin/types as IAccount

      • account IAccount

        • address String

        • network String

        • contract String optional

          • token contract address. (@wepin/types(from version 0.0.12 and above) is defined in IAccount.)

    • If networks aren't passed, it returns a Promise object resolved with array of account of all networks.

    • Example

      [
          {
              "address": "0x0000001111112222223333334444445555556666",
              "network": "Ethereum"
          },
          {
              "address": "0x0000001111112222223333334444445555556666",
              "network": "Ethereum",
              "contract": "0x777777888888999999000000111111222222333333",
          },
      ]
  • Promise <void>

    • If user is not logged in, it returns Promise.

getStatus (Supported from version 0.0.6-alpha and above.)

var status = wepin.getStatus()

The getStatus() method returns lifecycle of wepin.

Returned Value

  • <WepinLifeCycle>

    • The WepinLifeCycle is defined at @wepin/types as (Supports version 0.0.7 and above.)

      • not_initialized: if wepin is not initialized

      • initializing: if wepin is initializing

      • initialized: if wepin is initialized

      • before_login: if wepin is initialized but the user is not logged in

      • login: if the user is logged in

login (Supported from version 0.0.6-alpha and above.)

var userInfo = await wepin.login()

The login() method returns information of the logged-in user. If a user is not logged in, Wepin widget will show login page.

Parameters

  • email <String> optional

    This parameter is used when attempting to log in with a specific email address.

Returned Value

Promise <IWepinUser>

  • Type of IWepinUser is defined in @wepin/types (Supported from version 0.0.8 and above.)

    • status String <'success'|'fail'>

    • userInfo Object (optional)

      • userId String

      • email String

      • provider String <'google'|'apple'|'email'|'naver'|'discord'|'external_token'>

    • Example

      {
          "status": "success",
          "userInfo": {
              "userID": "123455",
              "email": "abc@test.com",
              "provider": "google"
          }
      }

logout (Supported from version 0.0.6-alpha and above.)

await wepin.logout()

The logout() method performs a wepin logout.

Returned Value

Promise <void>

signUpWithEmailAndPassword (Supported from version 0.0.9-alpha and above.)

It makes users sign up with Wepin using email and password.

const result = await wepin.signUpWithEmailAndPassword('test@test.com', 'abcd1234')

Parameters

  • email <String>

    User's Email Address

  • password <String>

    User's Password

Returned Value

Promise <boolean>

Exceptions

loginWithEmailAndPassword (Supported from version 0.0.9-alpha and above.)

It makes users login with Wepin using email and password.

const result = await wepin.loginWithEmailAndPassword('test@test.com', 'abcd1234')

Parameters

  • email <String>

    User's Email Address

  • password <String>

    User's Password

Returned Value

Promise <IWepinUser>

  • Type of IWepinUser is defined in @wepin/types (Supported from version 0.0.8 and above.)

    • status String <'success'|'fail'>

    • userInfo Object (optional)

      • userId String

      • email String

      • provider <'email'>

  • Example

    {
    	status: 'success',
    	userInfo: {
    		userID: '123455',
    		email: 'test@test.com',
    		provider: 'email'
            }
    }

Exceptions

  • require/wepin-register: If this exception occurs, you should execute the wepin.register(pin) method.

register (Supported from version 0.0.9-alpha and above.)

The Wepin service creates a wallet and registers the user's PIN. After the sign-up and login processes are successfully completed, the Wepin service performs the registration process.

const result = await wepin.register('12345678')

Parameters

  • pin <String>

    The user's wallet PIN number

Returned Value

Promise <boolean>

  • If the registration process is successfully completed, it returns true.

  • After a successful registration, you should perform the login process once again.

Exceptions

getBalance (Supported from version 0.0.9-alpha and above.)

It returns the account balance information. This action can only be performed after logging in.

const result = wepin.getBalance({
  address: '0x0000001111112222223333334444445555556666',
  network: 'Ethereum',
})

Parameters

  • account <IAccount>

Returned value

  • Promise <IAccountBalance>

    • Type of IAccountBalance and ITokenBalance is defined in @wepin/types (Support from version 0.0.8)

      • symbol <string> - symbol of account

      • balance <string> - balance of account

      • tokens <Array<ITokenBalance>> - token balance information for account

        • name <string> - token name

        • contract <string> - token contract address

        • symbol <string> - token symbol

        • balance <string> - token balance

    • Example

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

Exceptions

loginWithExternalToken (Supported from version 0.0.19-alpha and above.)

await wepin.loginWithExternalToken(token, sign, withUI?)

It logs in to the Wepin with external token(e.g., idToken). The loginWithExternalToken() method returns information of the logged-in user.

If the user is not registered on Wepin, and the withUI value is set to true, the registration page will be displayed in the widget. However, if the withUI value is set to false or not defined, a require/wepin-register exception will be triggered.

Parameters

  • token <string>

    • External token value to be used for login (e.g., idToken).

  • sign <string>

    • Signature value for the token provided as the first parameter. (Signature Generation Methods)

    • The key for signing can be obtained from Wepin Workspace. In the Development Tools menu, click Get your authentication key on the Login tab to retrieve the authentication key.

  • withUI <boolean> optional

    • Indicates whether to display the Wepin widget screen if registration is required.

Returned Value

  • Promise <IWepinUser>

    • Type of IWepinUser is defined in @wepin/types (Supports version 0.0.7 and above.)

      • status <'success'|'fail'>

      • userInfo <object> optional

        • userId <string>

        • email <string>

        • provider <'external_token'>

    • Example

      {
      	status: 'success',
      	userInfo: {
      		userID: '123455',
      		email: 'abc@test.com',
      		provider: 'external_token'
              }
      }

Exceptions

  • require/wepin-register : If this error occurs, you have to perform the wepin.register(pin) method.

send (Supported from version 0.0.20-alpha and above.)

await wepin.send(account, options?)

The "send" is performed using the widget, and returns the ID information of the "send" transaction. It can only be used after logging into Wepin.

Parameters

  • account <IAccount> - User email

  • options <ISendOptions> - The information required for the "send".

    • The ISendOptions is defined at @wepin/types.

      • toAddress <string> - The address to send tokens

      • amount <string> - The amount of tokens to send (in network units)

Example

// without options
const result = wepin.send({
  address: '0x0000001111112222223333334444445555556666',
  network: 'Ethereum',
})

// with options
const result = wepin.send(
  {
    address: '0x0000001111112222223333334444445555556666',
    network: 'Ethereum',
  },
  { amount: '0.1', toAddress: '0x777777888888999999000000111111222222333333' }
)

Return Value

  • Promise <string>

    • txID (Transaction ID) of the "send" transaction

    • Example

      '0x0000001111112222223333334444445555556666.............aaaaaabbbbbbccccccddddddeeeeeeffffff'

Exceptions

Exceptions

The error message types of the admin method are as follows.

Last updated