// Check for any existing wallet
do {
let exists = try await portal.doesWalletExist()
if exists {
print("Wallet exists with completed signing shares")
} else {
print("No wallet found or no completed signing shares")
}
} catch {
print("Error checking wallet existence: \(error)")
}
// Check for specific chain wallets
do {
// Check Ethereum wallet
let ethExists = try await portal.doesWalletExist("eip155:1")
if ethExists {
print("Ethereum wallet exists")
}
// Check Solana wallet
let solExists = try await portal.doesWalletExist("solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp")
if solExists {
print("Solana wallet exists")
}
} catch {
print("Error checking chain-specific wallets: \(error)")
}
// Complete example with wallet creation flow
do {
let exists = try await portal.doesWalletExist()
if !exists {
// Create new wallet if none exists
let newWallet = try await portal.createWallet { status in
print("Creation status: \(status)")
}
print("Created new wallet with ETH address: \(newWallet.ethereum)")
// Backup the wallet
let backup = try await portal.backupWallet(.iCloud) { status in
print("Backup status: \(status)")
}
try await backup.storageCallback()
} else {
// Wallet exists, fetch addresses
let addresses = try await portal.getAddresses()
if let ethAddress = addresses[.eip155] {
print("Existing ETH address: \(ethAddress ?? "Not found")")
}
}
} catch {
print("Error in wallet management flow: \(error)")
}