> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CrossmintSDK

> Swift Class

**Class**

The main entry point for interacting with the Crossmint SDK.

```swift theme={null}
@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:

```swift theme={null}
let sdk = CrossmintSDK.shared(apiKey: "your-api-key")
```

Then use the SDK to access wallets and authentication:

```swift theme={null}
// Get or create a wallet
let wallet = try await sdk.crossmintWallets.getOrCreateWallet(
    type: .evm,
    linkedUser: "user@example.com"
)

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

## Initialization

### shared

Returns the shared SDK instance.

```swift theme={null}
@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.

```swift theme={null}
@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.

```swift theme={null}
@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.

```swift theme={null}
@MainActor let crossmintWallets: CrossmintWallets
```

Use this property to create, retrieve, and manage smart wallets across supported blockchains (EVM, Solana).

```swift theme={null}
let wallet = try await CrossmintSDK.shared.crossmintWallets.getOrCreateWallet(
    type: .evm,
    linkedUser: "user@example.com"
)
```

### authManager

Manages user authentication and session state.

```swift theme={null}
@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.

```swift theme={null}
@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

### isOTPRequired

A publisher that emits `true` when OTP verification is required.

```swift theme={null}
@MainActor var isOTPRequired: Published<Bool>.Publisher { get }
```

Subscribe to this publisher to present an OTP input UI when the SDK requires additional verification for sensitive operations.

```swift theme={null}
struct ContentView: View {
    @ObservedObject var sdk = CrossmintSDK.shared
    @State private var showOTPSheet = false

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

### submit(otp:)

Submits an OTP code for verification.

```swift theme={null}
@MainActor func submit(otp: String)
```

Call this method when the user enters their OTP code in response to `isOTPRequired` emitting `true`.

#### Parameters

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

### cancelTransaction()

Cancels the current transaction requiring OTP verification.

```swift theme={null}
@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.

```swift theme={null}
@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.

```swift theme={null}
@MainActor var isProductionEnvironment: Bool { get }
```

Returns `true` if using a production API key, `false` for staging/development keys.
