# Android

## Wallet SDK - Android

The Wallet SDK provides an easy way to connect to user wallets and manage user sessions.

💡ROLLUPS THIS SDK SUPPORTS

* XpansionChain

⚠️THIS SDK IS UNSTABLEThis SDK is not yet at v1.0 so its public interface should not be considered final. Future releases may include breaking changes without further notice. We will do our best to keep this documentation updated providing visibility on breaking changes planned.CONTENTS

* <mark style="color:blue;">Setup</mark>
  * <mark style="color:blue;">Requirements</mark>
  * <mark style="color:blue;">Install</mark>
* <mark style="color:blue;">Connect wallet</mark>
  * <mark style="color:blue;">Connect via WalletConnect</mark>
* <mark style="color:blue;">Handle callbacks</mark>
  * <mark style="color:blue;">Set callback</mark>
  * <mark style="color:blue;">Remove callback</mark>
  * <mark style="color:blue;">Restart existing session</mark>
* <mark style="color:blue;">Disconnect wallet</mark>
* <mark style="color:blue;">Usage with the Core SDK</mark>
* <mark style="color:blue;">Further documentation</mark>

***

📚SDK LINKS

* <mark style="color:blue;">SDK reference</mark>

### Setup[​](https://docs.x.immutable.com/docs/sdks/wallet/android#setup) <a href="#setup" id="setup"></a>

#### Requirements[​](https://docs.x.immutable.com/docs/sdks/wallet/android#requirements) <a href="#requirements" id="requirements"></a>

* Android version 8.1 (API 27) and above

#### Install[​](https://docs.x.immutable.com/docs/sdks/wallet/android#install) <a href="#install" id="install"></a>

1. Add Maven Central and JitPack to your repositories

```
repositories {
    mavenCentral()
    maven { url = "https://jitpack.io" } // Needed for WalletConnect
}
```

2. Add dependency to your app `build.gradle` file:

```
dependencies {
    implementation 'com.XpansionChain.wallet:imx-wallet-sdk-android:$version'
}
```

3. In your `Application` class:

```
class ExampleApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    XpansionChainWallet.init(this)
  }
}
```

### Connect wallet[​](https://docs.x.immutable.com/docs/sdks/wallet/android#connect-wallet) <a href="#connect-wallet" id="connect-wallet"></a>

#### Connect via WalletConnect[​](https://docs.x.immutable.com/docs/sdks/wallet/android#connect-via-walletconnect) <a href="#connect-via-walletconnect" id="connect-via-walletconnect"></a>

Any wallet that supports <mark style="color:blue;">WalletConnect v1.0</mark> can be connected

```
XpansionChainWallet.connect(
    Provider.WalletConnect(
        appUrl = "https://www.marketplace.com/",
        appName = "My NFT Marketplace",
        appDescription = "This is a marketplace where all my favorite NFTs can be traded.",
        appIcons = listOf("http://www.marketplace.com/appicon.svg")
    )
)
```

If you want to use your own bridge server instead of the default provide it via `bridgeServerUrl` when connecting. For more info on how WalletConnect and the bridge works <mark style="color:blue;">see here</mark>.

### Handle callbacks[​](https://docs.x.immutable.com/docs/sdks/wallet/android#handle-callbacks) <a href="#handle-callbacks" id="handle-callbacks"></a>

All the XpansionChain`Wallet` methods (connect, disconnect, etc.) are asynchronous, and changes to the status are communicated via the callback.

#### Set callback[​](https://docs.x.immutable.com/docs/sdks/wallet/android#set-callback) <a href="#set-callback" id="set-callback"></a>

```
XpansionChainWallet.setCallback(object: XpansionChainWalletCallback {
    override fun onStatus(status: XpansionChainWalletStatus?, throwable: Throwable?) {
        when (status) {
            XpansionChainWalletStatus.Connected -> { showProfileScreen() }
            XpansionChainWalletStatus.Disconnected -> { showLoginScreen() }
           XpansionChainWalletStatus.Connecting -> { showProgressScreen() }
            is XpansionChainWalletStatus.PendingConnection -> { showConnectPopup(status.intent) }
            is XpansionChainWalletStatus.PendingSignature -> { showSignaturePopup(status.intent) }
        }
    }
})
```

**Pending states**[**​**](https://docs.x.immutable.com/docs/sdks/wallet/android#pending-states)

If a wallet app has been launched to connect or sign and your app has resumed but no result has arrived, `PendingConnection` or `PendingSignature` will be sent to the callback.

This allows you to handle this scenario flexibly; you could use the provided intent to prompt the user to re-launch their wallet and complete the flow or continue showing a waiting state.

#### Remove callback[​](https://docs.x.immutable.com/docs/sdks/wallet/android#remove-callback) <a href="#remove-callback" id="remove-callback"></a>

```
XpansionChainWallet.removeCallback()
```

#### Restart existing session[​](https://docs.x.immutable.com/docs/sdks/wallet/android#restart-existing-session) <a href="#restart-existing-session" id="restart-existing-session"></a>

The users previous wallet sessions will be automatically restored once your first activity is launched however it can also be manually triggered.

```
XpansionChainWallet.restartSession()
```

### Disconnect wallet[​](https://docs.x.immutable.com/docs/sdks/wallet/android#disconnect-wallet) <a href="#disconnect-wallet" id="disconnect-wallet"></a>

```
XpansionChainWallet.disconnect()
```

### Usage with the Core SDK[​](https://docs.x.immutable.com/docs/sdks/wallet/android#usage-with-the-core-sdk) <a href="#usage-with-the-core-sdk" id="usage-with-the-core-sdk"></a>

Wallet SDK Android is designed to be used in tandem with the <mark style="color:blue;">XpansionChain Core SDK for Kotlin/JVM</mark>.

Once you connect a user's wallet with the Wallet SDK you can provide the `Signer` and `StarkSigner` instances to Core SDK workflows.

```
val signer = XpansionChainWallet.signer
val starkSigner = XpansionChainWallet.starkSigner
if (signer != null && starkSigner != null) {
    XpansionChain.createTrade(orderId, emptyList(), signer, starkSigner).whenComplete { ... }
} else {
    // handle not connected
}
```

### Further documentation[​](https://docs.x.immutable.com/docs/sdks/wallet/android#further-documentation) <a href="#further-documentation" id="further-documentation"></a>

Check out the U<mark style="color:blue;">I guide for implementing user wallet interactions.</mark>

* See the <mark style="color:blue;">Developer homepage</mark> for general information on building on XpansionChain.
* Build on XpansionChain zkEVM:
  * <mark style="color:blue;">Documentation</mark>
  * <mark style="color:blue;">API reference</mark>
  * <mark style="color:blue;">Support</mark>
* Build on XpansionChain:
  * <mark style="color:blue;">Documentation</mark>
  * <mark style="color:blue;">API reference</mark>
  * <mark style="color:blue;">Support</mark>


---

# 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://xpansionchain-1.gitbook.io/xpansionchain/sdks/wallet-sdk/android.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.
