import DynamicSDKSwift
import SwiftUI
// Initialize the SDK at app launch
@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() }
}
}
// Access the SDK singleton
let sdk = DynamicSDK.instance()
// Use built-in authentication UI
sdk.ui.showAuth()
// Or authenticate programmatically with email OTP
try await sdk.auth.email.sendOTP(email: "user@example.com")
try await sdk.auth.email.verifyOTP(token: "123456")
// Social authentication
try await sdk.auth.social.connect(provider: .google) // or .apple, .farcaster
// Access authenticated user
if let user = sdk.auth.authenticatedUser {
print("Welcome \(user.email ?? "")")
}
// Get user wallets (automatically created after authentication)
let wallets = sdk.wallets.userWallets
// Get wallet balance
if let wallet = wallets.first {
let balance = try await sdk.wallets.getBalance(wallet: wallet)
print("Balance: \(balance)")
}
// Sign a message
let signature = try await sdk.wallets.signMessage(wallet: wallet, message: "Hello!")
// Send EVM transaction
let transaction = EthereumTransaction(
to: recipientAddress,
value: amountInWei,
gasLimit: 21000,
maxFeePerGas: gasPrice,
maxPriorityFeePerGas: gasPrice
)
let txHash = try await sdk.evm.sendTransaction(transaction: transaction, wallet: wallet)
print("Transaction sent: \(txHash)")
// Logout
try await sdk.auth.logout()