SdkUser

Represents an authenticated user in the Dynamic system.
public struct SdkUser {
    public let id: String
    public let email: String?
    public let phoneNumber: String?
    public let verifiedCredentials: [JwtVerifiedCredential]?
    public let token: String?
    public let projectSettings: ProjectSettings?
    // ... other properties
}

Properties

  • id (String) - User’s unique identifier
  • email (String?) - User’s email address (optional)
  • phoneNumber (String?) - User’s phone number (optional)
  • verifiedCredentials ([JwtVerifiedCredential]?) - Array of user’s verified credentials
  • token (String?) - User’s authentication token
  • projectSettings (ProjectSettings?) - Project configuration settings

Example

if let currentUser = dynamicClient.user {
    print("User ID: \(currentUser.id)")
    print("Email: \(currentUser.email ?? "Not provided")")
    print("Phone: \(currentUser.phoneNumber ?? "Not provided")")
    print("Token: \(currentUser.token ?? "No token")")

    if let credentials = currentUser.verifiedCredentials {
        print("Verified credentials: \(credentials.count)")
    }

    if let settings = currentUser.projectSettings {
        print("Project: \(settings.general.displayName ?? "Unknown")")
    }
}

JwtVerifiedCredential

Represents a verified credential associated with a user in JWT format.
public struct JwtVerifiedCredential {
    public let id: String
    public let format: CredentialFormat
    public let oauthProvider: OAuthProvider?
    public let walletProvider: WalletProvider?
    public let walletName: String?
    public let chain: String?
    public let publicIdentifier: String?
    public let walletProperties: WalletProperties?
    // ... other properties
}

Properties

  • id (String) - Credential’s unique identifier
  • format (CredentialFormat) - Type of credential format
  • oauthProvider (OAuthProvider?) - OAuth provider type
  • walletProvider (WalletProvider?) - Wallet provider type
  • walletName (String?) - Name of the wallet
  • chain (String?) - Blockchain chain identifier
  • publicIdentifier (String?) - Public identifier (e.g., wallet address)
  • walletProperties (WalletProperties?) - Additional wallet properties

Example

if let verifiedCredentials = dynamicClient.user?.verifiedCredentials {
    for credential in verifiedCredentials {
        print("Credential ID: \(credential.id)")
        print("Format: \(credential.format.rawValue)")

        if let oauthProvider = credential.oauthProvider {
            print("OAuth Provider: \(oauthProvider.rawValue)")
        }

        if let walletProvider = credential.walletProvider {
            print("Wallet Provider: \(walletProvider.rawValue)")
        }

        if let walletName = credential.walletName {
            print("Wallet Name: \(walletName)")
        }

        if let chain = credential.chain {
            print("Chain: \(chain)")
        }

        if let publicIdentifier = credential.publicIdentifier {
            print("Public Identifier: \(publicIdentifier)")
        }
    }
}

CredentialFormat

Enumeration of credential formats.
public enum CredentialFormat: String {
    case blockchain = "blockchain"
    case oauth = "oauth"
    // ... other formats
}

WalletProvider

Enumeration of wallet providers.
public enum WalletProvider: String {
    case dynamic = "dynamic"
    case metamask = "metamask"
    case walletconnect = "walletconnect"
    // ... other providers
}

OTPVerification

Represents the state of an OTP verification process.
public struct OTPVerification {
    public let email: String?
    public let phoneNumber: String?
    public let phoneCountryCode: String?
    public let isoCountryCode: String?
    public let verificationUUID: String
}

Properties

  • email (String?) - Email address (for email OTP)
  • phoneNumber (String?) - Phone number (for SMS OTP)
  • phoneCountryCode (String?) - Country code (for SMS OTP)
  • isoCountryCode (String?) - ISO country code (for SMS OTP)
  • verificationUUID (String) - Unique identifier for this verification

Example

// Email OTP verification
let emailOtp = OTPVerification(
    email: "[email protected]",
    phoneNumber: nil,
    phoneCountryCode: nil,
    isoCountryCode: nil,
    verificationUUID: "uuid-123"
)

// SMS OTP verification
let smsOtp = OTPVerification(
    email: nil,
    phoneNumber: "1234567890",
    phoneCountryCode: "+1",
    isoCountryCode: "US",
    verificationUUID: "uuid-456"
)

ProviderType

Enumeration of supported social authentication providers.
public enum ProviderType: String {
    case apple = "apple"
    case google = "google"
    case twitter = "twitter"
    case discord = "discord"
    case github = "github"
    case twitch = "twitch"
    case facebook = "facebook"
    case farcaster = "farcaster"
    // ... other providers
}

Example

let provider: ProviderType = .google

switch provider {
case .apple:
    print("Apple ID")
case .google:
    print("Google account")
case .twitter:
    print("Twitter account")
case .discord:
    print("Discord account")
case .github:
    print("GitHub account")
case .twitch:
    print("Twitch account")
case .facebook:
    print("Facebook account")
case .farcaster:
    print("Farcaster account")
default:
    print("Other provider")
}

BlockchainAddress

Cross-chain compatible blockchain address.
public struct BlockchainAddress {
    public func asString() -> String
}

Methods

asString

Get the string representation of the blockchain address.
public func asString() -> String

Returns

  • String - Address in string format

Example

let blockchainAddress = ethereumWallet.accountAddress
let addressString = blockchainAddress.asString()
print("Blockchain Address: \(addressString)")

KeyShares

Represents wallet key shares for embedded wallets.
public struct KeyShares {
    public let id: Uuid
    // Key shares implementation details
}

Usage

func checkKeySharesAvailability(client: DynamicClient, walletAddress: String) -> Bool {
    let keyShares = loadKeyShares(client: client, accountAddress: walletAddress)
    return keyShares != nil
}

let hasKeyShares = checkKeySharesAvailability(
    client: dynamicClient,
    walletAddress: ethereumWallet.address.asString()
)

print("Key shares available: \(hasKeyShares)")

BigUInt

Large unsigned integer type for handling blockchain values.
// Wei amounts (1 ETH = 10^18 Wei)
let oneEthInWei = BigUInt(1000000000000000000)
let halfEthInWei = BigUInt(500000000000000000)

// Gas limits
let standardGasLimit = BigUInt(21_000)
let erc20GasLimit = BigUInt(65_000)

// Chain IDs
let sepoliaChainId = BigUInt(11155111)
let mainnetChainId = BigUInt(1)

Data

Swift’s Data type for handling binary data in transactions.
// Empty data for ETH transfers
let emptyData = Data()

// Custom data for contract interactions
let customData = Data([0x12, 0x34, 0x56, 0x78])

// String to data conversion
let messageData = "Hello".data(using: .utf8) ?? Data()

Error Types

Common Error Patterns

do {
    let result = try await someSDKFunction()
} catch {
    if let nsError = error as NSError? {
        switch nsError.code {
        case 1003:
            print("Could not determine wallet ID from address")
        case 1004:
            print("Invalid OTP code")
        case 1005:
            print("Network error")
        default:
            print("Unknown error: \(error)")
        }
    } else {
        print("Error: \(error)")
    }
}