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

# Client & Configuration

## DynamicSDK.initialize

Initialize the Dynamic SDK. This must be called once at app launch, before any SwiftUI views access the SDK.

```swift theme={"system"}
DynamicSDK.initialize(props: ClientProps) -> DynamicSDK
```

### Parameters

* **props** (ClientProps) - Configuration object with environment settings

### Returns

* **DynamicSDK** - Initialized SDK instance

### Example

```swift theme={"system"}
import SwiftUI
import DynamicSDKSwift

@main
struct YourApp: App {
    init() {
        _ = DynamicSDK.initialize(
            props: ClientProps(
                environmentId: "YOUR_ENVIRONMENT_ID",
                appLogoUrl: "https://yourdomain.com/logo.png",
                appName: "Your App Name",
                redirectUrl: "yourapp://",
                appOrigin: "https://yourdomain.com"
            )
        )
    }

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

## DynamicSDK.instance

Get the SDK singleton instance. Only call after `initialize()` has been called.

```swift theme={"system"}
DynamicSDK.instance() -> DynamicSDK
```

### Returns

* **DynamicSDK** - The SDK singleton instance

### Example

```swift theme={"system"}
let sdk = DynamicSDK.instance()

// Access SDK modules
let user = sdk.auth.authenticatedUser
let wallets = sdk.wallets.userWallets
```

## ClientProps

Configuration object for initializing the Dynamic SDK.

```swift theme={"system"}
ClientProps(
    environmentId: String,
    appLogoUrl: String,
    appName: String,
    redirectUrl: String,
    appOrigin: String,
    logLevel: LogLevel? = nil,
    debug: ClientDebugProps? = nil,
    reownProjectId: String? = nil
)
```

### Properties

| Property         | Type              | Required | Description                                                                                             |
| ---------------- | ----------------- | -------- | ------------------------------------------------------------------------------------------------------- |
| `environmentId`  | String            | Yes      | Your Dynamic environment ID from the dashboard                                                          |
| `appLogoUrl`     | String            | Yes      | URL to your app's logo (shown in auth UI)                                                               |
| `appName`        | String            | Yes      | Your app's display name                                                                                 |
| `redirectUrl`    | String            | Yes      | Deep link URL scheme for callbacks (e.g., `yourapp://`)                                                 |
| `appOrigin`      | String            | Yes      | Your app's origin URL                                                                                   |
| `reownProjectId` | String?           | No       | Reown (WalletConnect) project ID for [connecting to dApps](/swift/wallets/global-wallets/walletconnect) |
| `logLevel`       | LogLevel?         | No       | Logging level (`.debug`, `.info`, `.warn`, `.error`)                                                    |
| `debug`          | ClientDebugProps? | No       | Debug options                                                                                           |

### Example

```swift theme={"system"}
// Basic configuration
let props = ClientProps(
    environmentId: "abc123-def456",
    appLogoUrl: "https://myapp.com/logo.png",
    appName: "My Web3 App",
    redirectUrl: "myapp://",
    appOrigin: "https://myapp.com"
)

// With debug options
let debugProps = ClientProps(
    environmentId: "abc123-def456",
    appLogoUrl: "https://myapp.com/logo.png",
    appName: "My Web3 App",
    redirectUrl: "myapp://",
    appOrigin: "https://myapp.com",
    logLevel: .debug,
    debug: ClientDebugProps(webview: true)
)
```

## ClientDebugProps

Debug configuration options.

```swift theme={"system"}
ClientDebugProps(
    webview: Bool = false
)
```

### Properties

* **webview** (Bool) - Enable WebView debugging

### Example

```swift theme={"system"}
let debug = ClientDebugProps(webview: true)
```

## SDK Modules

After initialization, the SDK provides access to various modules:

```swift theme={"system"}
let sdk = DynamicSDK.instance()

// Authentication
sdk.auth                    // Authentication methods and state
sdk.auth.email              // Email OTP methods
sdk.auth.sms                // SMS OTP methods
sdk.auth.social             // Social authentication
sdk.auth.passkey            // Passkey authentication
sdk.auth.externalAuth       // External JWT authentication

// Wallets
sdk.wallets                 // Wallet management
sdk.wallets.userWallets     // Current user's wallets
sdk.wallets.userWalletsChanges  // Combine publisher for wallet updates

// Blockchain
sdk.evm                     // EVM chain operations
sdk.solana                  // Solana operations
sdk.networks                // Available networks
sdk.networks.evm            // EVM networks
sdk.networks.solana         // Solana networks

// Security
sdk.mfa                     // Multi-factor authentication
sdk.passkeys                // Passkey management

// UI
sdk.ui                      // Built-in UI components
sdk.ui.showAuth()           // Show authentication UI
sdk.ui.showUserProfile()    // Show user profile
```

## Environment Setup

### URL Scheme Configuration

Add a URL scheme to your `Info.plist` for authentication callbacks:

```xml theme={"system"}
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.yourapp</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>yourapp</string>
        </array>
    </dict>
</array>
```

### Dashboard Configuration

1. Set your `redirectUrl` to match your URL scheme (e.g., `yourapp://`)
2. Whitelist your deep link URL in Dynamic dashboard under **Security → Whitelist Mobile Deeplink**

## Complete Setup Example

```swift theme={"system"}
import SwiftUI
import DynamicSDKSwift
import Combine

@main
struct MyApp: App {
    init() {
        _ = DynamicSDK.initialize(
            props: ClientProps(
                environmentId: "YOUR_ENV_ID",
                appLogoUrl: "https://example.com/logo.png",
                appName: "My App",
                redirectUrl: "myapp://",
                appOrigin: "https://example.com",
                logLevel: .info
            )
        )
    }

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

struct RootView: View {
    @State private var isAuthenticated = false
    @State private var cancellables = Set<AnyCancellable>()

    private let sdk = DynamicSDK.instance()

    var body: some View {
        Group {
            if isAuthenticated {
                HomeView()
            } else {
                LoginView()
            }
        }
        .onAppear {
            // Check current state
            isAuthenticated = sdk.auth.authenticatedUser != nil

            // Listen for changes
            sdk.auth.authenticatedUserChanges
                .receive(on: DispatchQueue.main)
                .sink { user in
                    isAuthenticated = user != nil
                }
                .store(in: &cancellables)
        }
    }
}
```
