import DynamicSwiftSDK
import SwiftUI
// Initialize the SDK with session state
let config = DynamicClientConfig(environmentId: "<your env id>")
let client = createDynamicClient(config: config)
let sessionState = DynamicSessionState()
bindSessionState(sessionState, to: client)
// Add Ethereum connector
try await addEthereumConnector(
to: client,
networkConfigProvider: GenericNetworkConfigurationProvider(),
initialChainId: 84532
)
// Authenticate a user with email OTP
let otpVerification = try await sendEmailOtp(
client: client,
email: "user@example.com"
)
let authenticatedUser = try await verifyOtp(
otpVerification: otpVerification,
verificationToken: "123456"
)
// Create a wallet for the user
let accountAddress = try await createWalletAccount(client: client)
// Initialize the wallet for transactions
let wallet = try EthereumWallet(address: accountAddress, client: client)
// Send a transaction
let transaction = EthereumTransaction(
from: wallet.address,
to: recipient,
value: amount,
data: Data(),
nonce: nil,
gasPrice: gasPrice,
gasLimit: gasLimit,
chainId: chainId
)
let txHash = try await wallet.sendTransaction(transaction)
print("Transaction sent: \(txHash)")
// Export private key (for backup)
let privateKey = try await wallet.exportPrivateKey()
print("Private key exported: \(privateKey)")