# Methods

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

## `openWidget`

```csharp
_wepin.openWidget();
```

The <mark style="color:blue;">`openWidget`</mark> method shows the widget window.

### Returned Value

* \<void>

## `closeWidget`

```csharp
_wepin.closeWidget();
```

The <mark style="color:blue;">`closeWidget`</mark> method closes the widget window.

### Returned value

* \<void>

## `getAccounts`

```javascript
_wepin.getAccounts();
```

The <mark style="color:blue;">`getAccounts`</mark> method returns user accounts of the networks available in the app. <mark style="color:blue;">`getAccounts`</mark> is a method available after widget login.

### Parameters

* **`networks`**: *Array of string*\
  It is the <mark style="color:blue;">`network`</mark> of the address you want to receive. If no <mark style="color:blue;">`network`</mark> is specified, all addresses available in the app are returned.\
  The names of blockchain networks that can be put into <mark style="color:blue;">`networks`</mark> can be found on the following page.

{% content-ref url="/pages/jNG611rZkq69C8zZKglh" %}
[Broken mention](broken://pages/jNG611rZkq69C8zZKglh)
{% endcontent-ref %}

### **Returned Value**

* `Promise` \<Array>
  * If a user is logged in, it returns a <mark style="color:blue;">`Promise`</mark> object resolved with array of <mark style="color:blue;">`account`</mark> of networks.
    * Type of <mark style="color:blue;">`account`</mark> is assigned at [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) as <mark style="color:blue;">`IAccount`</mark>
    * `account` *IAccount*<br>
      * `address` *String*
      * `network` *String*
      * `contract` *String* *optional*&#x20;
        * token contract address. ([`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types)(from version `0.0.12` and above) is defined in `IAccount`.)
  * If <mark style="color:blue;">`networks`</mark> aren't passed, it returns a <mark style="color:blue;">`Promise`</mark> object resolved with array of <mark style="color:blue;">`account`</mark> of all networks.
  * Example

    ```json
    [
        {
            "address": "0x0000001111112222223333334444445555556666",
            "network": "Ethereum"
        },
        {
            "address": "0x0000001111112222223333334444445555556666",
            "network": "Ethereum",
            "contract": "0x777777888888999999000000111111222222333333",
        },
    ]
    ```
* `Promise` \<void>

  * If user is not logged in, it returns <mark style="color:blue;">`Promise`</mark>.

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

```javascript
var status = wepin.getStatus()
```

The <mark style="color:blue;">`getStatus()`</mark> method returns lifecycle of <mark style="color:blue;">`wepin`</mark>.

### **Returned Value**

* \<WepinLifeCycle>
  * The <mark style="color:blue;">`WepinLifeCycle`</mark> is defined at  [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-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.)

```javascript
var userInfo = await wepin.login()
```

The <mark style="color:blue;">`login()`</mark> 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 <mark style="color:blue;">`IWepinUser`</mark> is defined in [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-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

    <pre class="language-json"><code class="lang-json"><strong>{
    </strong>    "status": "success",
        "userInfo": {
            "userID": "123455",
            "email": "abc@test.com",
            "provider": "google"
        }
    }
    </code></pre>

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

```javascript
await wepin.logout()
```

The <mark style="color:blue;">`logout()`</mark> 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.

<pre class="language-javascript"><code class="lang-javascript"><strong>const result = await wepin.signUpWithEmailAndPassword('test@test.com', 'abcd1234')
</strong></code></pre>

### **Parameters**

* `email` *\<String>*

  User's Email Address
* `password` *\<String>*

  User's Password

### **Returned Value**

`Promise` *\<boolean>*

[#exceptions](#exceptions "mention")

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

It makes users login with Wepin using email and password.

<pre class="language-javascript"><code class="lang-javascript"><strong>const result = await wepin.loginWithEmailAndPassword('test@test.com', 'abcd1234')
</strong></code></pre>

### **Parameters**

* `email` *\<String>*

  User's Email Address
* `password` *\<String>*

  User's Password

### **Returned Value**

`Promise` *\<IWepinUser>*

* Type of <mark style="color:blue;">`IWepinUser`</mark> is defined in [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) (Supported from version `0.0.8` and above.)
  * `status` *String <'success'|'fail'>*
  * `userInfo` *Object (optional)*
    * `userId` *String*
    * `email` *String*
    * `provider` *<'email'>*
* *Example*

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

[#exceptions](#exceptions "mention")

* `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.

```javascript
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](#exceptions "mention")

## `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.

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

### **Parameters**

* `account` <*`IAccount`*>&#x20;
  * Type of `IAccount` is defined in [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types)

### **Returned value**

* `Promise` <*`IAccountBalance`*>
  * Type of `IAccountBalance` and `ITokenBalance` is defined in [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-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

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

[#exceptions](#exceptions "mention")

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

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

It logs in to the Wepin with external token(e.g., <mark style="color:blue;">`idToken`</mark>). The <mark style="color:blue;">`loginWithExternalToken()`</mark> 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](https://github.com/WepinWallet/wepin-widget-js-sdk/blob/main/doc/SignatureGenerationMethods.md))
  * The key for signing can be obtained from [Wepin Workspace](https://workspace.wepin.io/). 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 <mark style="color:blue;">`IWepinUser`</mark> is defined in [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-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](#exceptions "mention")

* `require/wepin-register` : If this error occurs, you have to perform the <mark style="color:blue;">`wepin.register(pin)`</mark> method.

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

```javascript
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
  * Type of <mark style="color:blue;">`IAccount`</mark> is defined in [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types)
* `options` <`ISendOptions`> - The information required for the "send".
  * The `ISendOptions` is defined at [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types).
    * `toAddress` <`string`> - The address to send tokens
    * `amount` <`string`> - The amount of tokens to send (in network units)

Example

```javascript
// 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

    ```javascript
    '0x0000001111112222223333334444445555556666.............aaaaaabbbbbbccccccddddddeeeeeeffffff'
    ```

[#exceptions](#exceptions "mention")

## Exceptions

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

<table><thead><tr><th width="290">Error Message</th><th>Description</th></tr></thead><tbody><tr><td>invalid/email-format</td><td>invalid email format</td></tr><tr><td>invalid/password-format</td><td>invalid password format (A minimum of 8 characters consisting of letters, numbers and special characters. )</td></tr><tr><td>invalid/pin-format</td><td>invalid PIN format (6-8 digit number) (*Do not use the same number more than four times when registering)</td></tr><tr><td>invalid/firebase-token</td><td>invalid firebase token</td></tr><tr><td>invalid/wepin-api-key</td><td>invalid wepin api key</td></tr><tr><td>invalid/account</td><td>invalid account</td></tr><tr><td>invalid/email-domain</td><td>invalid email domain</td></tr><tr><td>invalid/to-address</td><td>invalid to address</td></tr><tr><td>auth/existed-email</td><td>existed email</td></tr><tr><td>auth/too-many-requests</td><td>too mandy firebase requests</td></tr><tr><td>auth/wrong-password</td><td>wrong password</td></tr><tr><td>auth/expired-token</td><td>expired login session</td></tr><tr><td>auth/unknown/${string}</td><td>unknown auth error</td></tr><tr><td>fail/send-email</td><td>failed to sent validation email</td></tr><tr><td>fail/reset-password</td><td>failed to set password</td></tr><tr><td>fail/email-verified</td><td>failed to verify email</td></tr><tr><td>fail/wepin-login</td><td>login wepin failed</td></tr><tr><td>fail/wepin-register</td><td>failed to register with wepin</td></tr><tr><td>fail/get-balance</td><td>failed to get balance</td></tr><tr><td>fail/check-email</td><td>failed to check email</td></tr><tr><td>fail/requireFee</td><td>insufficient fee</td></tr><tr><td>fail/requireNetworkFee</td><td>insufficient network fee(only token transaction request)</td></tr><tr><td>require/email-verified</td><td>email verification required</td></tr><tr><td>require/signup</td><td>wepin sign-up required</td></tr><tr><td>require/wepin-register</td><td>wepin registration required</td></tr><tr><td>require/login</td><td>wepin login required</td></tr><tr><td>unknown/${string}</td><td>unknown error</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/en/deprecated/react-native-sdk/method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
