Methods
Here are the methods provided by the Wepin Widget JavaScript SDK.
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
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
closeWidget
It closes the widget window. Logging out is not performed even if the window is closed.
Parameters
<void>
Return Value
<void>
Example
loginWithUI
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> optionaluserId
<string>The user ID in Wepin
email
<string> The email address of the logged-in userprovider
<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> optionalWhether the user's PIN number is required
walletId
<string>The wallet ID of the Wepin user
Example
response
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> optionaluserId
<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> optionalWhether the user's PIN number is required.
walletId
<string>The wallet ID of the Wepin user
Example
logout
It logs out the Wepin user.
Parameters
<void>
Return Value
Promise
<void>
Example
getAccounts
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> optionalnetworks
<string[]> optional It's the networks of the accounts to to be returned. The blockchain networks that can be put innetworks
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
response
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[]> optionalnetwork
<string> The network type of the user account to query the balanceaddress
<string>The address of the user account to query the balance
isAA
<boolean> optionalWhether 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
response
send
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> optionalto
<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
response
finalize
It terminates the use of WepinSDK. The WepinLifeCycle
changes to not_initialized
.
Return Value
void
Example
Last updated