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

  • Setup

    • Requirements

    • Install

  • Connect wallet

    • Connect via WalletConnect

  • Handle callbacks

    • Set callback

    • Remove callback

    • Restart existing session

  • Disconnect wallet

  • Usage with the Core SDK

  • Further documentation


📚SDK LINKS

  • SDK reference

Setup

Requirements

  • Android version 8.1 (API 27) and above

Install

  1. Add Maven Central and JitPack to your repositories

repositories {
    mavenCentral()
    maven { url = "https://jitpack.io" } // Needed for WalletConnect
}
  1. Add dependency to your app build.gradle file:

dependencies {
    implementation 'com.XpansionChain.wallet:imx-wallet-sdk-android:$version'
}
  1. In your Application class:

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

Connect wallet

Connect via WalletConnect

Any wallet that supports WalletConnect v1.0 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 see here.

Handle callbacks

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

Set callback

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

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

XpansionChainWallet.removeCallback()

Restart existing session

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

XpansionChainWallet.disconnect()

Usage with the Core SDK

Wallet SDK Android is designed to be used in tandem with the XpansionChain Core SDK for Kotlin/JVM.

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

Check out the UI guide for implementing user wallet interactions.

  • See the Developer homepage for general information on building on XpansionChain.

  • Build on XpansionChain zkEVM:

    • Documentation

    • API reference

    • Support

  • Build on XpansionChain:

    • Documentation

    • API reference

    • Support

Last updated