Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

DynamicSDK.initialize

Initialize the Dynamic SDK. This must be called once at app launch, before any SwiftUI views access the SDK.
DynamicSDK.initialize(props: ClientProps) -> DynamicSDK

Parameters

  • props (ClientProps) - Configuration object with environment settings

Returns

  • DynamicSDK - Initialized SDK instance

Example

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.
DynamicSDK.instance() -> DynamicSDK

Returns

  • DynamicSDK - The SDK singleton instance

Example

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.
ClientProps(
    environmentId: String,
    appLogoUrl: String,
    appName: String,
    redirectUrl: String,
    appOrigin: String,
    logLevel: LogLevel? = nil,
    debug: ClientDebugProps? = nil
)

Properties

PropertyTypeRequiredDescription
environmentIdStringYesYour Dynamic environment ID from the dashboard
appLogoUrlStringYesURL to your app’s logo (shown in auth UI)
appNameStringYesYour app’s display name
redirectUrlStringYesDeep link URL scheme for callbacks (e.g., yourapp://)
appOriginStringYesYour app’s origin URL
logLevelLogLevel?NoLogging level (.debug, .info, .warn, .error)
debugClientDebugProps?NoDebug options

Example

// 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.
ClientDebugProps(
    webview: Bool = false
)

Properties

  • webview (Bool) - Enable WebView debugging

Example

let debug = ClientDebugProps(webview: true)

SDK Modules

After initialization, the SDK provides access to various modules:
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:
<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

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)
        }
    }
}