# Methods

## changeLanguage

```kotlin
fun changeLanguage(options: WidgetAttributes)
```

To modify the widget's properties such as language and currency

**Parameters**

* **attributes** `<WidgetAttributes>`
  * **defaultLanguage** \<String>\
    Set the default language of the widget. The default value is `ko`, and currently supported languages are `en` and `ko.`
  * **defaultCurrency** `<String>`\
    Set the default currency of the widget. The default value is `KRW`, and currently supported currencies are `USD` and `KRW.`

**Returns**

* None

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.changeLanguage(WidgetAttributes(defaultLanguage = "ko", defaultCurrency = "KRW"))
```

## getStatus

```kotlin
suspend fun getStatus(): WepinLifeCycle {
```

Returns the lifecycle status of the WepinSDK.

**Parameters**

* None

**Returns**

* **\<WepinLifeCycle>**
  * **NOT\_INITIALIZED** - WepinSDK has not been initialized.
  * **INITIALIZING** - WepinSDK is in the process of initializing.
  * **INITIALIZED -** WepinSDK has been successfully initialized.
  * **BEFORE\_LOGIN** - WepinSDK is initialized, but the user is not logged in.
  * **LOGIN** - The user is logged in and registered with Wepin.
  * **LOGIN\_BEFORE\_REGISTER** - The user is logged in but not registered with Wepin.

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
coroutineScope.launch {
    val status = wepinWidgetSDK.getStatus()
}
```

## login

The `login` variable is a Wepin login library that includes various authentication methods, allowing users to log in using different approaches. It supports email and password login, OAuth provider login, login using ID tokens or access tokens, and more. For detailed information on each method, refer to the official [Login Library guide](https://docs.wepin.io/en/widget-integration/compose-multiplatform-sdk/login-library).

#### **Available Methods**

* [`loginWithOauthProvider`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#loginwithoauthprovider)
* [`signUpWithEmailAndPassword`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#signupwithemailandpassword)
* [`loginWithEmailAndPassword`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#loginwithemailandpassword)
* [`loginWithIdToken`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#loginwithidtoken)
* [`loginWithAccessToken`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#loginwithaccesstoken)
* [`getRefreshFirebaseToken`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#getrefreshfirebasetoken)&#x20;
* #### [`loginFirebaseWithOauthProvider`](https://docs.wepin.io/en/widget-integration/login-library/methods#loginfirebasewithoauthprovider)
* #### [`loginWepinWithOauthProvider`](https://docs.wepin.io/en/widget-integration/login-library/methods#loginwepinwithoauthprovider)
* #### [`loginWepinWithEmailAndPassword`](https://docs.wepin.io/en/widget-integration/login-library/methods#loginwepinwithemailandpassword)
* #### [`loginWepinWithIdToken`](https://docs.wepin.io/en/widget-integration/login-library/methods#loginwepinwithidtoken)
* #### [`loginWepinWithAccessToken`](https://docs.wepin.io/en/widget-integration/login-library/methods#loginwepinwithaccesstoken)
* [`loginWepin`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#loginwepin)
* [`getCurrentWepinUser`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#getcurrentwepinuser)
* [`logout`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#logoutwepin)
* [`getSignForLogin`](https://docs.wepin.io/en/ios-swift-sdk/login-library/method#getsignforlogin)

These methods support various login scenarios, allowing you to select the appropriate method based on your needs

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
coroutineScope.launch { 
    //WepinLogin instance generate
    val wepinLogin: WepinLogin = WepinLogin(
        WepinLoginOptions(
            context = context,
            appId = appId,
            appKey = appKey
        )
    )
    //WepinLogin initialization
    wepinLogin.init()
    {
        //Log in using an OAuth Provider
        val response = wepinLogin.loginWithOauthProvider(
            LoginOauth2Params(
                provider = "google",
                clientId = "your-google-client-id"
            )
        )
        //Get the sign
        val sign = wepinLogin.getSignForLogin(
            privateKeyHex = "private key", 
            message = response.token
        )
        var loginResult: LoginResult? = null
        if (response.provider == "naver" || response.provider = "discord") {
            //Log in using an Access Token
            loginResult = wepinLogin.loginWithAccessToken(
                LoginOauthAccessTokenRequest(
                    provider = response.provider,
                    token = response.token,
                    sign = sign
                )
            )
        } else {
            //Log in using an ID Token
            loginResult = wepinLogin.loginWithIdToken(
                LoginOauthIdTokenRequest(
                    idToken = response.token,
                    sign = sign
                )
            )
        }
    }
    or 
    {
        //Log in using email and password
        val loginResult = wepinLogin.loginWithEmailAndPassword(
            LoginWithEmailParams(
                email = "abc@defg.kr",
                password = "abcdefg$"
            )
        )
    }
    //Wepin Login
    val userInfo = wepinLogin.loginWepin(loginResult)
}
```

## loginWithUI

Supported from version *\`0.0.3* and later.

```kotlin
suspend fun loginWithUI(parameter: LoginWithUIParameter): WepinUser?
```

The `loginWithUI` method provides the functionality to log in using a widget and returns the information of the logged-in user. If a user is already logged in, the widget will not be displayed, and the method will directely return the logged-in user's information. To perform a login without the widget, use the loginWepin() method from the login variable instead.

{% hint style="info" %}
This method can only be used after the authentication key has been deleted from the [Wepin Workspace](https://workspace.wepin.io/)(Wepin Workspace > Developer Tools menu > Login tab > Auth Key > Delete). The Auth Key menu is visible only if an authentication key was previously generated.
{% endhint %}

**Parameters**

* **LoginWithUIParameter**
  * **loginProviders** `<Array>`

    An array of login providers to configure the widget. If an empty array is provided, only the email login function is available.

    * **provider** `<String>`\
      The OAuth login provider (e.g., 'google', 'discord', 'naver', 'apple').
    * **clientId** `<String>`\
      The client ID of the OAuth login provider.

**Returns**

* **\<WepinUser>** (*optional*)
  * **status** `<'success' | 'fail'>`\
    The login status
  * **userInfo** `<UserInfo>` (*optional*)\
    The user's information, including:
    * **userId** `<String>`\
      The user's ID
    * **email** `<String>`\
      The user's email
    * **provider** `<'google'|'naver'|'discord'|'apple'|'email' | 'external_token'>`\
      The login provider
    * **use2FA** `<Boolean>`\
      Whether the user uses two-factor authentication
  * **walletId** `<String>`\
    The user's wallet ID
  * **userStatus** `<UserStatus>` (*optional*)\
    The user's Wepin login status, including:
    * **loginStatus** `<WepinLoginStatus - 'complete' | 'pinRequired' | 'registerRequired'>`\
      If the user's `loginStatus` value is not 'complete', the user must register with Wepin.
    * **pinRequired** `<Boolean>`\
      Whether a PIN is required
  * **token** `<Token>`\
    The user's Wepin token
    * **accessToken** `<String>`\
      The access token
    * **refreshToken** `<String>`\
      The refresh token

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
val options = LoginWithUIParameter(
  email = "User Email Address",
  loginProviders = arrayOf(
    LoginProvider(provider = "google", clientId = "GOOGLE_CLIENT_ID"),
    LoginProvider(provider = "discord", clientId = "DISCORD_CLIENT_ID"),
    LoginProvider(provider = "naver", clientId = "NAVER_CLIENT_ID")
  )
)
wepinWidgetSDK.loginWithUI(options)
```

## openWidget

```kotlin
suspend fun openWidget()
```

Opens the widget window. If the user is not logged in, the widget window will not open. Therefore, the user must be logged in to Wepin before calling `openWidget`. To log in to Wepin, use the `loginWepin` method from the `login` variable.

**Parameters**

* None

**Returns**

* None

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.openWidget()
```

## closeWidget

```kotlin
fun closeWidget()
```

Closes the widget window. Closing the window does not log out the user.

**Parameters**

* None

**Returns**

* None

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.closeWidget()
```

## register

```kotlin
suspend fun register(): WepinUser?
```

Registers the user with Wepin. After signing up and logging in, the Wepin widget’s registration page opens, allowing the user to register (create a wallet and account) with Wepin services. This function can only be used when `WepinLifeCycle` is `loginBeforeRegister`. After calling the `loginWepin()` method from the `login` variable, if the `loginStatus` value in `userStatus` is not 'complete', this method should be called

**Parameters**

* None

**Returns**

* **\<WepinUser>**&#x20;
  * **status** `<'success' | 'fail'>`\
    The login status
  * **userInfo** `<UserInfo>` (*optional*)\
    The user's information, including:
    * **userId** `<String>`\
      The user's ID
    * **email** `<String>`\
      The user's email
    * **provider** `<'google' | 'apple' | 'naver' | 'discord' | 'email' | 'external_token'>`\
      The login provider
    * **use2FA** `<Boolean>`\
      Whether the user uses two-factor authentication
  * **walletId** `<String>`\
    The user's wallet ID
  * **userStatus** `<UserStatus>` (*optional*)\
    The user's Wepin login status, including:
    * **loginStatus** `<WepinLoginStatus - 'complete' | 'pinRequired' | 'registerRequired'>`\
      If the user's `loginStatus` value is not 'complete', the user must register with Wepin.
    * **pinRequired** `<Boolean>`\
      Whether a PIN is required
  * **token** `<Token>`\
    The user's Wepin token
    * **accessToken** `<String>`\
      The access token
    * **refreshToken** `<String>`\
      The refresh token

**Exception**

* [WepinError](#wepinerror)

**Example**

<pre class="language-kotlin"><code class="lang-kotlin"><strong>coroutineScope.launch {
</strong>    wepinWidget.register()
}
</code></pre>

## getAccounts

```kotlin
suspend fun getAccounts(networks: List<String>? = null, withEoa: Boolean? = null): ArrayList<Account>?
```

Returns the user's account information (networks and addresses) available in the app. This function can only be used after logging in to Wepin. If no parameters are provided, it returns information for all the user's accounts.

**Parameters**

* **networks** `<List<String>>` *optional*\
  The networks for which you want to return account information. The supported blockchain networks can be found on the supported blockchain page
* **withEoa** `<Boolean>` *optional*\
  If AA accounts are present, this determines whether to include EOA accounts in the return.

{% content-ref url="../../../wepin/supported-blockchains" %}
[supported-blockchains](https://docs.wepin.io/en/wepin/supported-blockchains)
{% endcontent-ref %}

**Returns**

* **\<ArrayList\<Account>>&#x20;*****optional***
  * **network** `<String>`\
    The network type of the user's account
  * **address** `<String>`\
    User account address
  * **contract** `<String>` *optional*\
    The contract address of the token
  * **isAA** `<Boolean>` *optional*\
    Indicates if it is an AA account

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
coroutineScope.launch {
    wepinWidget.getAccounts(
        networks: listOf("Ethereum"),
        withEoa: true
    )
}
```

## getBalance

```kotlin
suspend fun getBalance(accounts: ArrayList<Account>): ArrayList<AccountBalanceInfo>
```

Returns the balance information (amount) of accounts. This function can only be used after logging in to Wepin. If no `accounts` parameter is provided, it returns the balance of all user accounts.

**Parameters**

* **accounts** `<ArrayList<Account>>`
  * **network** `<String>`\
    The network type of the account for which to check the balance
  * **address** `<String>`\
    The address of the account for which to check the balance
  * **contract** `<String>` *optional*\
    The contract address of the token
  * **isAA** `<Boolean>` *optional*\
    Indicates if it is an AA account

**Returns**

* **\<ArrayList\<AccountBalanceInfo>>**&#x20;
  * **address** `<String>`\
    The network type of the user's account
  * **network** `<String>`\
    The address of the user's account
  * **symbol** `<String>`\
    Network symbol
  * **balance** `<String>`\
    The amount of the network coin held
  * **tokens** `<TokenBalanceInfo>`
    * **symbol** `<String>`\
      Token symbol
    * **balance** `<String>`\
      The amount of the token held
    * **contract** `<String>`\
      Token contract address

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
coroutineScope.launch {
    val accountList: ArrayList<Account> = wepinWidget.getAccounts()
    wepinWidget.getBalance(accountList)
}
```

## getNFTs

```kotlin
suspend fun getNFTs(refresh: Boolean, networks: List<String>? = null): ArrayList<WepinNFT>
```

Returns the user's NFTs. This function can only be used after logging in to Wepin. If no `networks` parameter is provided, it returns all of the user's NFT information.

**Parameters**

* **refresh** `<Boolean>` *optional*\
  Required parameter to indicate whether to refresh the NFT data
* **networks** `<List<String>>`\
  A list of network names to filter the NFTs

**Returns**

* **\<ArrayList\<WepinNFT>>**
  * **account** `<Account>`
    * **network** `<String>`\
      The network type of the account for which to check the balance
    * **address** `<String>`\
      The address of the account for which to check the balance
    * **contract** `<String>` *optional*\
      The contract address of the token
    * **isAA** `<Boolean>` *optional*\
      Indicates if it is an AA account
  * **contract** `<WepinNFTContract>`
    * **name** `<String>`\
      NFT contract name
    * **address** `<String>`\
      NFT contract address
    * **scheme** `<String>`\
      Scheme of the NFT
    * **description** `<String>` *optional*\
      Description of the NFT contract
    * **network** `<String>`\
      Network associated with the NFT contract
    * **externalLink** `<String>` *optional*\
      External link associated with the NFT contract
    * **imageUrl** `<String>` *optional*\
      Image URL associated with the NFT contract
  * **name** `<String>`\
    Name of the NFT
  * **description** `<String>`\
    Description of the NFT
  * **externalLink** `<String>`\
    External link associated with the NFT
  * **imageUrl** `<String>`\
    Image URL associated with the NFT
  * **contentUrl** `<String>` *optional*\
    URL pointing to the content associated with the NFT
  * **quantity** `<Int>`\
    Quantity of the NFT
  * **contentType** `<String>`\
    Content type of the NFT ('image' | 'video')
  * **state** `<Int>`\
    State of the NFT

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
coroutineScope.launch {
    wepinWidget.getNFTs(
        refresh = true,
        networks = listOf("Ethereum")
    )
}
```

## send

```kotlin
suspend fun send(sendData: SendData): SendResponse
```

Performs the send function using the widget and returns the ID information of the send transaction. This function can only be used after logging in to Wepin.

**Parameters**

* **sendData** `<SendData>`
  * **account** `<Account>`\
    The user's account information to send from
    * **network** `<String>`\
      The network type of the account for which to check the balance
    * **address** `<String>`\
      The address of the account for which to check the balance
    * **contract** `<String>` *optional*\
      The contract address of the token
    * **isAA** `<Boolean>` *optional*\
      Indicates if it is an AA account
  * **txData** `<TxData>`
    * **toAddress** `<String>`\
      The address to send to
    * **amount** `<String>`\
      The amount to send

**Returns**

* **\<SendResponse>**
  * **txId** `<String>`\
    The transaction ID of the send transaction

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
coroutineScope.launch {
    val result = wepinWidgetSDK.send(
        SendData(
            account = Account(
                network = "Ethereum",
                address = "0x0000001111112222223333334444445555556666"
            ),
            txData = TxData(
                toAddress = "0x9999991111112222223333334444445555556666",
                amount = "0.1"
            )
        )
    )
}
```

## receive

Supported from version *\`0.0.3* and later.

```kotlin
suspend fun receive(account: Account): ReceiveResponse
```

The `receive` method opens the receive page associated with the specified account. This method can only be used after logging into Wepin.

**Parameters**

* **\<Account>** \
  Provides the account information for the page that will be opend.
  * **network** `<String>`\
    The network associated with the account.
  * **address** `<String>`\
    The address of the account.
  * **contract** `<String>` *optional*\
    The contract address of the token.

**Returns**

* **\<ReceiveResponse>** \
  response containing the Account Info.
  * **account**\
    the account information for the page that was opend.
    * **network** `<String>`\
      The network associated with the account.
    * **address** `<String>`\
      The address of the account.
    * **contract** `<String>` *optional*\
      The contract address of the token

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.receive(account = account!!)
```

## viewAccountDetail

Supported from version *\`0.0.4* and later.

```kotlin
suspend fun viewAccountDetail(account: Account): AccountDetailResponse
```

The `viewAccountDetail` method opens the account information page associated with the specified account. This method can only be used after logging into Wepin.

**Parameters**

* **\<Account>** \
  Provides the account information for the page that will be opend.
  * **network** `<String>`\
    The network associated with the account.
  * **address** `<String>`\
    The address of the account.
  * **contract** `<String>` *optional*\
    The contract address of the token.

**Returns**

* **\<AccountDetailResponse>** \
  response containing the Account Info.
  * **account**\
    the account information for the page that was opend.
    * **network** `<String>`\
      The network associated with the account.
    * **address** `<String>`\
      The address of the account.
    * **contract** `<String>` *optional*\
      The contract address of the token

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.viewAccountDetail(account = account!!)
```

## verifyPin

Supported from version *\`0.0.3* and later.

```kotlin
suspend fun verifyPin(count: Int = 1): Boolean
```

The `verifyPin` method displays a screen where the user can input their PIN and verifies whether the entered PIN is correct.

**Parameters**

* **None**

**Returns**

* \<Boolean> \
  `true` is correct Pin

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.verifyPin()
```

## finalize

```kotlin
fun finalize()
```

Terminates the use of WepinSDK. The `WepinLifeCycle` changes to `notInitialized`.

**Parameters**

* None

**Returns**

* None

**Exception**

* [WepinError](#wepinerror)

**Example**

```kotlin
wepinWidgetSDK.finalize()
```

## WepinError

| Error Code                    | Error Message                 | Error Description                                                                                                                                                                                    |
| ----------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `invalidAppKey`               | "InvalidAppKey"               | The Wepin app key is invalid.                                                                                                                                                                        |
| `invalidParameters` \`        | "InvalidParameters"           | One or more parameters provided are invalid or missing.                                                                                                                                              |
| `invalidLoginProvider`        | "InvalidLoginProvider"        | The login provider specified is not supported or is invalid.                                                                                                                                         |
| `invalidToken`                | "InvalidToken"                | The token does not exist.                                                                                                                                                                            |
| `invalidLoginSession`         | "InvalidLoginSession"         | The login session information does not exist.                                                                                                                                                        |
| `notInitialized`              | "NotInitialized"              | The WepinLoginLibrary has not been properly initialized.                                                                                                                                             |
| `alreadyInitialized`          | "AlreadyInitialized"          | The WepinLoginLibrary is already initialized, so the logout operation cannot be performed again.                                                                                                     |
| `userCancelled`               | "UserCancelled"               | The user has cancelled the operation.                                                                                                                                                                |
| `unknownError`                | "UnknownError"                | An unknown error has occurred, and the cause is not identified.                                                                                                                                      |
| `notConnectedInternet`        | "NotConnectedInternet"        | The system is unable to detect an active internet connection.                                                                                                                                        |
| `failedLogin`                 | "FailedLogin"                 | The login attempt has failed due to incorrect credentials or other issues.                                                                                                                           |
| `alreadyLogout`               | "AlreadyLogout"               | The user is already logged out, so the logout operation cannot be performed again.                                                                                                                   |
| `invalidEmailDomain`          | "InvalidEmailDomain"          | The provided email address's domain is not allowed or recognized by the system.                                                                                                                      |
| `failedSendEmail`             | "FailedSendEmail"             | The system encountered an error while sending an email. This is because the email address is invalid or we sent verification emails too often. Please change your email or try again after 1 minute. |
| `requiredEmailVerified`       | "RequiredEmailVerified"       | Email verification is required to proceed with the requested operation.                                                                                                                              |
| `incorrectEmailForm`          | "incorrectEmailForm"          | The provided email address does not match the expected format.                                                                                                                                       |
| `incorrectPasswordForm`       | "IncorrectPasswordForm"       | The provided password does not meet the required format or criteria.                                                                                                                                 |
| `notInitializedNetwork`       | "NotInitializedNetwork"       | The network or connection required for the operation has not been properly initialized.                                                                                                              |
| `requiredSignupEmail`         | "RequiredSignupEmail"         | The user needs to sign up with an email address to proceed.                                                                                                                                          |
| `failedEmailVerified`         | "FailedEmailVerified"         | The WepinLoginLibrary encountered an issue while attempting to verify the provided email address.                                                                                                    |
| `failedPasswordStateSetting`  | "FailedPasswordStateSetting"  | Failed to set the password state. This error may occur during password management operations, potentially due to invalid input or system issues.                                                     |
| `failedPasswordSetting`       | "failedPasswordSetting"       | Failed to set the password. This could be due to issues with the provided password or internal errors during the password setting process.                                                           |
| `existedEmail`                | "ExistedEmail"                | The provided email address is already registered. This error occurs when attempting to sign up with an email that is already in use.                                                                 |
| `apiRequestError`             | "ApiRequestError"             | There was an error while making the API request. This can happen due to network issues, invalid endpoints, or server errors.                                                                         |
| `incorrectLifecycleException` | "IncorrectLifecycleException" | The lifecycle of the Wepin SDK is incorrect for the requested operation. Ensure that the SDK is in the correct state (e.g., `initialized` and `login`) before proceeding.                            |
| `failedRegister`              | "FailedRegister"              | Failed to register the user. This can occur due to issues with the provided registration details or internal errors during the registration process.                                                 |
| `accountNotFound`             | "AccountNotFound"             | The specified account was not found. This error is returned when attempting to access an account that does not exist in the Wepin.                                                                   |
| `nftNotFound`                 | "NftNotFound"                 | The specified NFT was not found. This error occurs when the requested NFT does not exist or is not accessible within the user's account.                                                             |
| `failedSend`                  | "FailedSend"                  | Failed to send the required data or request. This error could be due to network issues, incorrect data, or internal server errors.                                                                   |
| `failedReceive`               | "FailedReceive"               | Failed to open the receive page. This error could be due to network issues, incorrect data, or internal server errors.                                                                               |
| `failedAppDetail`             | "FailedViewAccountDetail"     | Failed to open the account detail page. This error could be due to network issues, incorrect data, or internal server errors.                                                                        |
| `failedPinVerified`           | "FailedToVerifyPin"           | Failed to verify pin. This error could be due to network issues, incorrect data, or internal server errors.                                                                                          |
