Overview
Use the CDP Swift SDK to add Coinbase Developer Platform (CDP) user wallets to your native iOS and macOS apps. Your Swift apps can leverage EVM Externally Owned Accounts (EOA), EVM Smart Accounts, and Solana Accounts through a single library target — CDPCore — that exposes an actor-based, async/await API.What makes Swift user wallets special?
What makes Swift user wallets special?
The CDP Swift SDK brings the same wallet infrastructure that powers our web and React Native SDKs to native Apple platforms with:
- Native performance: Built for iOS and macOS, no JavaScript bridge.
- Async/await first:
WalletsClientis anactorand every public method isasync. - Apple platform services: Keychain-backed session storage, Apple Crypto, and
ASWebAuthenticationSession-based OAuth are auto-registered onstart(). - Swappable services: Replace storage, crypto, or OAuth implementations via
PlatformRegistryfor full control.
Prerequisites
- A free CDP Portal account.
- Xcode 15 or later.
- An iOS Simulator (bundled with Xcode) or a physical iOS/macOS device.
Minimum version requirements
| Xcode | 15.0 |
| Swift | 5.9 |
| iOS | 16.0 |
| macOS | 13.0 |
1. Set up your Swift project
Copy your Project ID
Navigate to the Security Configuration page in CDP Portal and copy your Project ID. You will use this in the next step when initializing the SDK.
Add the CDP Swift SDK
The SDK is published via Swift Package Manager from the public Or add it directly to your Then add the
coinbase/cdp-swift repository.In Xcode, choose File → Add Package Dependencies… and enter the repository URL:Package.swift:CDPCore product to your target:Initialize the SDK
Create a
WalletsClient, call start() to restore any persisted session and register the default Apple platform services (Keychain, crypto, OAuth), and forward OAuth redirects to handleOAuthCode(url:).Configure OAuth redirects (social login)
OAuth/social login (Google, Apple, Telegram, etc.) runs through
ASWebAuthenticationSession, which presents the provider, captures the redirect at {callbackURLScheme}://cdp-oauth-callback, and completes the flow internally.-
Set the
callbackURLSchemeonCDPCoreConfig. It defaults to your app’s bundle identifier (Bundle.main.bundleIdentifier), so set it explicitly only if you want a different scheme: -
Navigate to the Security Configuration in CDP Portal and add the full redirect URL
myapp://cdp-oauth-callbackto your allowed domains.
The host segment
cdp-oauth-callback is fixed by the SDK. The backend matches the full scheme://host value — myapp://cdp-oauth-callback — against your project’s allowed origins, so allowlist the entire value, not just the scheme.Email and SMS authentication work without any OAuth configuration. These redirect settings are only relevant to OAuth/social login on Apple platforms.
Optional: deep-link fallback
ASWebAuthenticationSession handles the default flow, but you can also register a custom URL scheme and forward the redirect to the SDK as a fallback (this mirrors the SDK’s example apps):- Add a
CFBundleURLTypesentry to your app’sInfo.plistwhoseCFBundleURLSchemesmatches yourcallbackURLScheme(for example,myapp). - Forward incoming URLs to
handleOAuthCode(url:)from.onOpenURL(see the initialization example).
start() restores any prior session and onAuthStateChange fires with the current User (or nil if signed out).
2. Sign in and send your first transaction
Now that the SDK is initialized, let’s authenticate, load a wallet, and send a transaction.Authenticate with email
Kick off an Email OTP flow, then verify the code your user receives:For social login, call The signed-in
signInWithOAuth. The SDK presents the provider with ASWebAuthenticationSession, captures the redirect at {callbackURLScheme}://cdp-oauth-callback, and verifies the result automatically:User arrives through onAuthStateChange once the flow completes. Make sure you have configured your OAuth redirect as described in Configure OAuth redirects.SMS OTP, OAuth, Sign-In With Ethereum (SIWE), and developer-issued JWT (BYO auth) are all supported. See Authentication methods for the full list.Load the user's wallet
With All account creation methods accept an optional
EthereumConfig(createOnLogin: .smart) set in the previous section, a smart account is automatically created the first time a user signs in. You can also create accounts on demand and read the current set of accounts from the User:idempotencyKey: String.Send your first transaction
Fund the wallet by visiting the CDP Portal Faucet and requesting Base Sepolia testnet ETH or USDC for your wallet address.For an EOA, broadcast a transaction directly:For a Smart Account, send a User Operation with gas sponsorship via the CDP paymaster:You’ve successfully created a user wallet and sent your first transaction natively on iOS!
Example apps
CDP Swift SDK
Browse the public Swift SDK repository for the full API surface, release notes, and a runnable SwiftUI demo in the SDK source tree.
What to read next
- Authentication methods: Learn about Email OTP, SMS OTP, OAuth, SIWE, and BYO auth flows.
- Smart Accounts: Learn about Smart Accounts and gas sponsorship via the CDP paymaster.