# 메서드

Wepin React Native SDK에서 제공하는 메서드입니다.

## openWidget

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

<mark style="color:blue;">`openWidget`</mark> 는 위젯 윈도우를 보여줍니다.&#x20;

### Return Value

* \<void>

## closeWidget

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

<mark style="color:blue;">`closeWidget`</mark> 는 위젯 윈도우를 닫습니다.

### Return value

* \<void>

## getAccounts

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

앱에서 사용 가능한 네트워크의 사용자 주소를 반환 합니다. <mark style="color:blue;">`getAccounts`</mark> 는 위젯 로그인 이후에 사용가능한 메서드입니다.&#x20;

### Parameters

* **networks**: *Array of string*\
  반환 받고자 하는 주소의 네트워크 입니다. 네트워크를 지정하지 않으면 앱에서 사용 가능한 모든 주소가 반환됩니다.\
  `networks` 에 넣을 수 있는 블록체인 네트워크의 이름은 아래의 페이지에서 확인 가능합니다.&#x20;

{% content-ref url="/pages/jNG611rZkq69C8zZKglh" %}
[지원 블록체인](/wepin/supported-blockchains.md)
{% endcontent-ref %}

### **Return Value**

* `Promise` \<Array>
  * 사용자가 로그인 한 경우,  네트워크의 계정 정보  `account` 가 반환됩니다.&#x20;
    * `account` s assigned at [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) as `IAccount`
    * `account` *IAccount*\
      [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) 선언되어 있습니다.&#x20;
      * `address` *String*
      * `network` *String*
      * `contract` *String* *optional*&#x20;
        * token contract address. ([`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types)(0.0.12 버전 이상)   `IAccount`에  정의되어 있습니다. )
  * `networks` 파라미터가 없는 경우에는 모든 계정 정보가 반환됩니다.&#x20;
  * Example

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

  * 사용자가 로그인 하지 않은 경우

## getStatus (0.0.6-alpha 버전 이상 지원)

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

위핀의 Lifecycle 상태 값을 반환합니다.   &#x20;

### **Return Value**

* \<WepinLifeCycle>
  * <mark style="color:blue;">`WepinLifeCycle`</mark> 는 [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) (0.0.7 버전 이상) 에 정의되어 있습니다.&#x20;
    * <mark style="color:blue;">`not_initialized`</mark>: if wepin is not initialized
    * <mark style="color:blue;">`initializing`</mark>: if wepin is initializing
    * <mark style="color:blue;">`initialized`</mark>: if wepin is initialized
    * <mark style="color:blue;">`before_login`</mark>: if wepin is initialized but the user is not logged in
    * <mark style="color:blue;">`login`</mark>: if the user is logged in

## login (0.0.6-alpha 버전 이상 지원)

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

사용자가 로그인하지 않은 경우 위젯 화면을 띄워 사용자 로그인을 요청합니다. 그리고 그 결과를 반환합니다.&#x20;

### Parameters

* `email` <*String> optional*

  특정 email 주소로 로그인 시도하려고 하는 경우 사용되는 파라미터 입니다.&#x20;

### **Return Value**

`Promise` \<IWepinUser>

* <mark style="color:blue;">`IWepinUser`</mark> 는 [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) (0.0.8 버전 이상)에 정의되어 있습니다.&#x20;
  * `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 (0.0.6-alpha 버전 이상 지원)

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

위핀 사용자 로그아웃을 합니다.&#x20;

### **Return Value**

`Promise` \<void>

## signUpWithEmailAndPassword (0.0.9-alpha 버전 이상 지원)

email과 password를 이용해서 위핀에 회원가입을 합니다.&#x20;

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

### **Parameters**

* email *\<String>*

  사용자의 email 주소
* password *\<String>*

  사용자의 비밀번호

### **Return Value**

`Promise` *\<boolean>*

[#exceptions](#exceptions "mention")

## loginWithEmailAndPassword (0.0.9-alpha 버전 이상 지원)

email과 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>*

  사용자의 email 주소
* password *\<String>*

  사용자의 비밀번호

### **Return Value**

`Promise` *\<IWepinUser>*

* <mark style="color:blue;">`IWepinUser`</mark> 는 [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) (0.0.8 버전 이상) 에 정의되어 있습니다.&#x20;
  * `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`: 해당 exception이 발생하면 `wepin.register(pin)` 메서드를 수행해야 합니다.

## register (0.0.9-alpha 버전 이상 지원)

위핀 서비스에 지갑을 생성하고 사용자의 PIN을 등록합니다. 회원가입과 로그인이 정상적으로 완료되고 나면 위핀 서비스는 register 과정을 수행합니다.&#x20;

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

### **Parameters**

* pin *\<String>*

  사용자의 지갑 PIN 번호

### **Return Value**

`Promise` *\<boolean>*

* register 과정이 정상적으로 마무리 되면 true가 리턴됩니다.
* register 를 성공하면 다시 한번 login을 수행해야 합니다.  &#x20;

[#exceptions](#exceptions "mention")

## getBalance (0.0.9-alpha 버전 이상 지원)

계정의 잔액 정보를 반환합니다. 로그인 이후에만 수행 가능합니다.&#x20;

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

### **Return 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** (0.0.19-alpha 버전  이상 지원)

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

External Token(예: idToken)을 이용하여 위핀에 로그인 합니다.

`loginWithExternalToken()` 메서드는 로그인한 사용자의 정보를 반환합니다.

사용자가 위핀에 등록되어 있지 않고, `withUI` 값이 `true`로 설정된 경우, 위젯에 등록 페이지가 표시됩니다. 그러나 `withUI` 값이 `false` 또는 정의되지 않은 경우, `require/wepin-register` 예외가 발생합니다.

### **Parameters**

* `token` \<string>
  * 로그인에 사용될 외부 토큰 값입니다. 예를 들어, idToken과 같은 값이 사용됩니다.
* `sign` \<string>
  * 첫 번째 매개변수로 제공된 토큰의 서명 값입니다. ([Signature Generation Methods](https://github.com/WepinWallet/wepin-widget-js-sdk/blob/main/doc/SignatureGenerationMethods.md))
  * 서명에 사용할 키는 [위핀 워크스페이스](https://workspace.wepin.io/login)에서 발급 받을 수 있습니다. 개발 도구 메뉴에서 로그인 탭의 인증키 발급 받기를 클릭하여 인증키를 확인하세요.
* `withUI` \<boolean> *optional*
  * 회원가입이 필요한 경우 위젯 화면을 표시할 지 여부를 나타냅니다.

### **Return Value**

* `Promise` \<IWepinUser>
  * <mark style="color:blue;">`IWepinUser`</mark>는 [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types) (0.0.7 버전 이상)에 정의되어 있습니다.&#x20;
    * `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`: 이 오류가 발생할 경우, `wepin.register(pin)` 메서드를 수행해야 합니다.

## send(0.0.20-alpha 버전 이상 지원)

```javascript
await wepin.send(account, options?)
```

widget을 이용하여 send기능을  수행하고 send transaction ID정보를 반환합니다. 위핀에 로그인한 후에만 사용할 수 있습니다.

### **Parameters**

* `account` <`IAccount`> - 사용자의 계정 정보
  * <mark style="color:blue;">`IAccount`</mark> 는 [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types)에 정의되어 있습니다.&#x20;
* `options` <`ISendOptions`> - 보내기 기능에 필요한 정보
  * `ISendOptions` 는 [`@wepin/types`](https://github.com/WepinWallet/wepin-js-sdk-types)에 정의되어 있습니다.&#x20;
    * `toAddress` <`string`> - 보낼 주소
    * `amount` <`string`> - 보낼 금액 (network 단위)

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`>
  * &#x20;send transaction ID
  * 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/deprecated/react-native-sdk/methods.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.
