Methods
The following shows the methods provided by the Wepin widget JavaScript SDK.
openWidget
openWidgetawait wepin.openWidget()The openWidget method shows the Wepin widget. The screen displayed in the widget window varies depending on the user's login status. If a user is not logged in, the Wepin widget will show them the login page.
Returned value
Promise<void>
closeWidget
closeWidgetwepin.closeWidget()The closeWidget method closes Wepin widget. Closing the window does not log users out.
getAccounts
getAccountslet accounts = await wepin.getAccounts(['Ethereum'])or
let accounts = await wepin.getAccounts()The getAccounts method returns user accounts of the networks available in the app. It's a method available after the widget login. The parameters are as follows.
Parameters
networks: Array of string It is thenetworkof the address you want to receive. If nonetworkis specified, all addresses available in the app are returned. The names of blockchain networks that can be put intonetworkscan be found on the following page.
Returned Value
Promise<Array>If a user is logged in, it returns a
Promiseobject resolved with array ofaccountof networks.Type of
accountis assigned at@wepin/typesasIAccountaccountStringaddressStringnetworkStringcontractString optionaltoken contract address. (
@wepin/types(0.0.12 버전 이상)IAccount에 정의되어 있습니다. )
If
networksaren't passed, it returns aPromiseobject resolved with array ofaccountof 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.3.1 and above.)
getStatus (Supported from version 0.3.1 and above.)var status = wepin.getStatus()The getStatus() method returns lifecycle of wepin.
Returned Value
<WepinLifeCycle>
The
WepinLifeCycleis defined at@wepin/typesas (Supports version 0.0.7 and above.)not_initialized: ifwepinis not initializedinitializing: ifwepinis initializinginitialized: ifwepinis initializedbefore_login: ifwepinis initialized but the user is not logged inlogin: if the user is logged in
login (Supported from version 0.3.1 and above.)
login (Supported from version 0.3.1 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.
Returned Value
Promise <IWepinUser>
Type of
IWepinUseris defined in@wepin/types(Supported from version0.0.7and above.)statusString <'success'|'fail'>userInfoObject (optional)userIdStringemailStringproviderString <'google'|'apple'>
Example
{ "status": "success", "userInfo": { "userID": "123455", "email": "[email protected]", "provider": "google" } }
logout (Supported from version 0.3.1 and above.)
logout (Supported from version 0.3.1 and above.)await wepin.logout()The logout() method performs a wepin logout .
Returned Value
Promise<void>
finalize (Supported from version 0.3.1 and above.)
finalize (Supported from version 0.3.1 and above.)wepin.finalize() The finalize() method finalizes the Wepin SDK. The state of wepin changes to not_initialized.
Returned Value
void
loginWithExternalToken (Supported from version 0.5.1 and above.)
loginWithExternalToken (Supported from version 0.5.1 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> optionalIndicates whether to display the Wepin widget screen if registration is required.
Returned Value
Promise<IWepinUser>Type of
IWepinUseris defined in@wepin/types(Supports version0.0.7and above.)status<'success'|'fail'>userInfo<object> optionaluserId<string>email<string>provider<'external_token'>
Example
{ status: 'success', userInfo: { userID: '123455', email: '[email protected]', provider: 'external_token' } }
require/wepin-register: If this error occurs, you have to perform thewepin.register(pin)method.
signUpWithEmailAndPassword (Supported from version 0.5.1 and above.)
signUpWithEmailAndPassword (Supported from version 0.5.1 and above.)await wepin.signUpWithEmailAndPassword(email, password)It signs up on the Wepin with your email and password.
Parameters
email<string> - User emailpassword<string> - User password
Returned Value
Promise<boolean>Returns true if the signup is successful.
Example
{ status: 'success', userInfo: { userID: '123455', email: '[email protected]', provider: 'external_token' } }
loginWithEmailAndPassword (Supported from version 0.5.1 and above.)
loginWithEmailAndPassword (Supported from version 0.5.1 and above.)await wepin.loginWithEmailAndPassword(email, password)It logs in to the Wepin with your email and password.
Parameters
email<string> - User emailpassword<string> - User password
Returned Value
Promise<IWepinUser>Type of
IWepinUseris defined in@wepin/types(Supported from version0.0.8and above.)status<'success'|'fail'>userInfo<object> optionaluserId<string>email<string>provider<'email'>
Example
{ status: 'success', userInfo: { userID: '123455', email: '[email protected]', provider: 'email' } }
require/wepin-register: If this error occurs, you have to perform thewepin.register(pin)method.
register (Supported from version 0.5.1 and above.)
register (Supported from version 0.5.1 and above.)await wepin.register(pin)It registers in the Wepin with a wallet pin.
After the signup and login are completed, the Wepin service registration (wallet and account creation) will proceed.
Parameters
pin<string> - Wallet PIN
Returned Value
Promise<boolean>Returns true if the registration is successful.
After successful registration, the
wepin.login(email, password)method has to be performed again.
getBalance (Supported from version 0.5.1 and above.)
getBalance (Supported from version 0.5.1 and above.)await wepin.getBalance(account)It returns the account balance information. It can be only usable after logging in through the widget.
Parameters
account<IAccount> - User emailType of
IAccountis defined in@wepin/types
Returned Value
Promise<IAccountBalance>Type of
IAccountBalanceandITokenBalanceis defined in@wepin/types(Supported from version0.0.8and above.)symbol<string> - symbol of the accountbalance<string> - balance of the accounttokens<Array<ITokenBalance>> - token balance information for the accountname<string> - token namecontract<string> - token contract addresssymbol<string> - token symbolbalance<string> - token balance
Example
{ symbol: 'ETH', balance: '1.1', tokens:[ { name: 'test', contract: '0x123...213', symbol: 'TEST', balance: '10' }, ] }
send (Supported from version 0.5.3 and above.)
send (Supported from version 0.5.3 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 emailType of
IAccountis defined in@wepin/types
options<ISendOptions> - The information required for the "send".The
ISendOptionsis defined at@wepin/types.toAddress<string> - The address to send tokensamount<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
The error message types of the admin method are as follows.
invalid/email-format
invalid email format
invalid/password-format
invalid password format (A minimum of 8 characters including letters, numbers and special characters. )
invalid/pin-format
invalid PIN format (6-8 digit number) (*Do not use the same number more than four times when registering)
invalid/firebase-token
invalid firebase token
invalid/wepin-api-key
invalid wepin api key
invalid/account
invalid account
invalid/email-domain
invalid email domain
invalid/to-address
invalid to address
auth/existed-email
existed email
auth/too-many-requests
too many firebase requests
auth/wrong-password
wrong password
auth/expired-token
expired login session
auth/unknown/${string}
unknown auth error
fail/send-email
failed to send validation email
fail/reset-password
failed to set password
fail/email-verified
failed to verify email
fail/wepin-login
failed to login to wepin
fail/wepin-register
failed to register with wepin
fail/get-balance
failed to get balance
fail/check-email
failed to check email
fail/requireFee
insufficient fee
fail/requireNetworkFee
insufficient network fee(only token transaction request)
require/email-verified
email verification required
require/signup
wepin sign-up required
require/wepin-register
wepin registration required
require/login
wepin login required
unknown/${string}
unknown error
Last updated
Was this helpful?