iOS

Wallet SDK - iOS

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

  • Installation

    • Supported wallet providers

    • Prerequisites

    • Cocoapods

  • Connect wallet

    • Connect via WalletConnect

    • Restart existing session

  • Disconnect wallet

  • Handle callbacks

    • Set callback

    • Pending states

    • Remove callback

  • Usage with the Core SDK

  • Further documentation


📚SDK LINKS

  • SDK reference

  • Github repository

Installation

This SDK is closed source and only available as a XCTFramework through Cocoapods.

Supported wallet providers

  • Any wallet that supports WalletConnect v1.0

Prerequisites

  • iOS 13.0

  • Swift 5.7

Cocoapods

In your Podfile:

# Important: ensure this source is specified in the Podfile
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '13.0'
use_frameworks!

target 'MyApp' do
  pod 'XpansionChainWallet'
end

Connect wallet

Connect via WalletConnect

try await XpansionChainWallet.shared.connect(
    to: .walletConnect(
        config: .init(
            appURL: URL(string: "https://XpansionChain.com")!,
            appName: "XpansionChain Sample",
            // The Universal Link or URL Scheme of the chosen wallet to be connected.
            walletDeeplink: "https://metamask.app.link"
        )
    )
)

NOTE: the async methods that require user actions with the chosen wallet app will only complete when the requested action has been performed (i.e. accepted or denied).

If you want to use your own bridge server instead of the default provide it via bridgeServer when connecting. For more info on how WalletConnect and the bridge works see here.

Restart existing session

The user's previous wallet sessions will be automatically restored when the app is launched, however it can also be manually triggered.

try await XpansionChainWallet.shared.restartSession()

Disconnect wallet

try await XpansionChainWallet.shared.disconnect()

Handle callbacks

All the XpansionChainWallet methods (connect, disconnect, etc.) are asynchronous, and will only return when they've completed the operation. If a user is taken to a wallet app for a connection or signature and does not perform the required operation, the request will not complete, leading to a pending state that is communicated via the callback.

Status callbacks are also useful for listening to status updates triggered from different screens.

Set callback

XpansionChainWallet.shared
    .setStatusCallbackForId("unique identifier") { status in
        switch status {
        case .connecting:
            // Waiting for a provider to connect or restarting a previous session.
            break

        case .pendingConnection:
            // Emitted when the app has returned to the foreground after triggering a connection request but doesn't have a
            // result yet.
            break

        case .pendingSignature:
            // Emitted when the app has returned to the foreground after triggering a signature request but doesn't have a
            // result yet.
            break

        case .connected:
            // An L1 wallet is connected and an L2 wallet is successfully derived.
            break

        case .disconnecting:
            // Waiting for a provider to disconnect.
            break

        case .disconnected:
            // A wallet moves from Connected to Disconnected. Failure to connect will throw an error.
            break
        }
}

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 re-launch their wallet and complete the flow, show a popup or continue showing a waiting state, for example.

Remove callback

You may unregister from all callbacks

XpansionChainWallet.shared.removeAllStatusCallbacks()

or remove a specific one

XpansionChainWallet.shared.removeStatusCallbackForId("unique identifier")

Usage with the Core SDK

This Wallet SDK is designed to be used in tandem with the XpansionChain Core SDK for Swift.

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

guard let signer = XpansionChainWallet.shared.signer, 
    let starkSigner = XpansionChainWallet.shared.starkSigner else {
    // handle not connected
    return
}

let result = try await XpansionChain.shared.createTrade(
    orderId: orderId, 
    signer: signer, 
    starkSigner: starkSigner
)

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