Skip to main content
Class The main entry point for interacting with the Crossmint SDK.
@MainActor final class CrossmintSDK
CrossmintSDK provides access to Crossmint’s wallet services, authentication, and blockchain functionality. Use the shared instance to integrate Crossmint features into your SwiftUI application. Initialize the SDK with your API key before accessing any functionality:
let sdk = CrossmintSDK.shared(apiKey: "your-api-key")
Then use the SDK to access wallets and authentication:
// Get or create a wallet
let wallet = try await sdk.crossmintWallets.getOrCreateWallet(
    type: .evm,
    linkedUser: "[email protected]"
)

// Sign a transaction
let signature = try await wallet.signTransaction(transaction)

Initialization

shared

Returns the shared SDK instance.
@MainActor static var shared: CrossmintSDK { get }
In debug builds, this property attempts to read the API key from the CROSSMINT_API_KEY environment variable. In release builds or if the environment variable is not set, accessing this property without first calling shared(apiKey:authManager:logLevel:) will cause a fatal error.
Info: Call shared(apiKey:authManager:logLevel:) to initialize the SDK before accessing this property in production.

shared(apiKey:authManager:logLevel:)

Initializes and returns the shared SDK instance with the specified configuration.
@MainActor static func shared(apiKey: String, authManager: AuthManager? = nil, logLevel: LogLevel = .error) -> CrossmintSDK
The shared CrossmintSDK instance. Call this method once during app startup to configure the SDK. Subsequent calls return the existing instance without reinitializing.
@main
struct MyApp: App {
    init() {
        _ = CrossmintSDK.shared(
            apiKey: "your-api-key",
            logLevel: .debug
        )
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Parameters

  • apiKey: Your Crossmint client API key.
  • authManager: An optional custom authentication manager. Pass nil to use the default.
  • logLevel: The logging verbosity level. Defaults to .error.

Services

crossmintWallets

Provides access to Crossmint wallet operations.
@MainActor let crossmintWallets: CrossmintWallets
Use this property to create, retrieve, and manage smart wallets across supported blockchains (EVM, Solana).
let wallet = try await CrossmintSDK.shared.crossmintWallets.getOrCreateWallet(
    type: .evm,
    linkedUser: "[email protected]"
)

authManager

Manages user authentication and session state.
@MainActor let authManager: AuthManager
Use this property to authenticate users, check login status, and manage sessions.

crossmintService

Provides low-level access to Crossmint API services.
@MainActor let crossmintService: CrossmintService
Most applications should use crossmintWallets and authManager instead. This property is available for advanced use cases requiring direct API access.

OTP Verification

isOTPRequred

A publisher that emits true when OTP verification is required.
@MainActor var isOTPRequred: Published<Bool>.Publisher { get }
Subscribe to this publisher to present an OTP input UI when the SDK requires additional verification for sensitive operations.
struct ContentView: View {
    @ObservedObject var sdk = CrossmintSDK.shared
    @State private var showOTPSheet = false

    var body: some View {
        MyContent()
            .onReceive(sdk.isOTPRequred) { required in
                showOTPSheet = required
            }
            .sheet(isPresented: $showOTPSheet) {
                OTPInputView()
            }
    }
}

submit(otp:)

Submits an OTP code for verification.
@MainActor func submit(otp: String)
Call this method when the user enters their OTP code in response to isOTPRequred emitting true.

Parameters

  • otp: The one-time password entered by the user.

cancelTransaction()

Cancels the current transaction requiring OTP verification.
@MainActor func cancelTransaction()
Call this method if the user dismisses the OTP input without entering a code.

Session Management

logout()

Logs out the current user and resets the SDK state.
@MainActor func logout() async throws
Call this method when the user signs out of your application to clear any cached authentication state and pending operations.

Instance Properties

isProductionEnvironment

Indicates whether the SDK is configured for the production environment.
@MainActor var isProductionEnvironment: Bool { get }
Returns true if using a production API key, false for staging/development keys.