The Capsule SDK for Swift allows you to easily integrate secure and scalable wallet functionalities into your iOS applications. This guide covers the installation, setup, and usage of the Capsule SDK, including handling authentication flows.

Prerequisites

To use Capsule, you need an API key. This key authenticates your requests to Capsule services and is essential for integration.

Don’t have an API key yet? Request access to the Developer Portal to create API keys, manage billing, teams, and more.

Setup

Beta Testing Credentials In the BETA Environment, you can use any email ending in @test.usecapsule.com (like dev@test.usecapsule.com) or US phone numbers (+1) in the format (area code)-555-xxxx (like (425)-555-1234). Any OTP code will work for verification with these test credentials. These credentials are for beta testing only. You can delete test users anytime in the beta developer console to free up user slots.

1

Add Capsule SDK as a Package Dependency

  1. In your Xcode project, go to Target -> MyApp -> General -> Frameworks, Libraries, and Embedded Content, and click the + symbol to add a new package dependency.
  1. On the next screen, click Add Other -> Add Package Dependency.
  1. Enter https://github.com/capsule-org/swift-sdk into the search field and select the dependency rule Up to Next Major Version. Ensure the range is 0.0.1 < 1.0.0.
  1. Add the package to the project MyApp.
  2. Ensure Add to Target has MyApp selected, and then click Add Package.
2

Initialize the Capsule SDK

Import the Capsule package and initialize it in your app.

ContentView.swift
import CapsuleSwift

struct ContentView: View {
    @Environment(\.authorizationController) private var authorizationController

    @StateObject var capsule = CapsuleSwift.Capsule(environment: .beta(jsBridgeUrl: nil), apiKey: "<YOUR_API_KEY>")
    @State private var email = ""

    var body: some View {
        ZStack {
            CapsuleWebView(viewModel: capsule).hidden()
            // Your UI components
        }
    }
}

Capsule offers two hosted environments: Environment.BETA (alias Environment.DEVELOPMENT) for testing, and Environment.PROD (alias Environment.PRODUCTION) for live use. Select the environment that matches your current development phase.

3

Implement User and Wallet Creation

UserCreation.swift
Button("Sign Up") {
    Task.init {
        try! await capsule.createUser(email: email)
    }
}
.buttonStyle(.bordered)
4

Enable User Login

UserLogin.swift
Button("Log In") {
    Task.init {
        try! await capsule.login(authorizationController: authorizationController)
    }
}

Examples

To help you get started with the Capsule Swift SDK, we’ve prepared a comprehensive example:

This example repository demonstrates how to handle user authentication, wallet creation, and signing messages using the Capsule SDK in a SwiftUI iOS application. It will help you understand how to seamlessly integrate Capsule into your project.

Next Steps

After integrating Capsule, you can explore other features and integrations to enhance your Capsule experience. Here are some resources to help you get started:

Ecosystems

Learn how to use Capsule with popular Web3 clients and wallet connectors. We’ll cover integration with key libraries for EVM, Solana, and Cosmos ecosystems.

If you’re ready to go live with your Capsule integration, make sure to review our go-live checklist:

Integration Support

If you’re experiencing issues that aren’t resolved by our troubleshooting resources, please contact our team for assistance. To help us resolve your issue quickly, please include the following information in your request:

  1. 1

    A detailed description of the problem you’re encountering.

  2. 2

    Any relevant error messages or logs.

  3. 3

    Steps to reproduce the issue.

  4. 4

    Details about your system or environment (e.g., device, operating system, software version).

Providing this information will enable our team to address your concerns more efficiently.