CDPCore — exposing an actor-based,
async/await API.
Quickstart
This guide will help you get started withCDPCore. You’ll learn how to install the
package, initialize the SDK, and make your first API call.
Requirements
- Swift 5.9+ (Xcode 15+)
- iOS 16+ / macOS 13+
Installation
Add the SDK to your Swift package dependencies:Gather your CDP Project information
- Sign in or create an account on the CDP Portal
- On your dashboard, select a project from the dropdown at the top, and copy the Project ID
Initialize the SDK
Before calling any methods in the SDK, you must first create aWalletsClient and call
start(). WalletsClient is an actor — every public method is async. Calling
start() restores any persisted session and registers the default Apple platform
services (Keychain, crypto, OAuth).
handleOAuthCode(url:) via .onOpenURL
(see OAuth).
Configuration
CDPCoreConfig controls SDK behaviour. Only projectId is required.
PlatformRegistry.shared.setPlatformServices(...) before start().
Account configuration
You can configure the SDK to create different types of accounts for new users. Smart Account configuration:ethereum.createOnLogin is set to .smart, the SDK will:
- Automatically create an EOA (Externally Owned Account) as the owner
- Create a Smart Account owned by that EOA
- Make both accounts available on the user object
createOnLogin entirely to prevent automatic account creation and instead create
accounts manually when needed (see Create Accounts Manually).
Sign In a User
The SDK supports five sign-in flows: Email OTP, SMS OTP, OAuth (Google/Apple/Telegram/…), Sign-In With Ethereum (SIWE), and developer-issued JWT (see Custom Authentication).Email OTP
SMS OTP
OAuth
signInWithOAuth returns a flow ID and opens the provider’s auth page. The provider
redirects back to your app via the URL scheme configured in
CDPCoreConfig.callbackURLScheme; forward that URL to handleOAuthCode (see
Initialize the SDK).
OAuth2ProviderType: .google, .apple, .telegram, plus
other configured providers.
For manual code exchange (no deep link):
Sign-In With Ethereum (SIWE)
Link Additional Authentication Methods
Once a user is authenticated, you can link additional auth methods to their account. This allows users to sign in using multiple methods (email, SMS, OAuth providers) with the same embedded wallet.Sign In with Custom Authentication
If you’re using a third-party identity provider (Auth0, Firebase, AWS Cognito, or any OIDC-compliant provider), you can authenticate users with JWTs from your provider.Prerequisites
Before using custom authentication:-
Configure your identity provider in the CDP Portal:
- Navigate to Embedded Wallet Configuration
- Click on the Custom auth tab
- Add your JWKS endpoint URL (e.g.,
https://your-domain.auth0.com/.well-known/jwks.json) - Configure your JWT issuer and audience
-
Provide a
customAuthclosure when initializing the SDK. The closure returns a fresh JWT from your identity provider, and the SDK invokes it automatically whenever a fresh bearer token is needed.
Authenticate a User
Once configured, callauthenticateWithJWT() to authenticate the user:
How it works
- Your user signs in to your identity provider (Auth0, Firebase, Cognito, etc.)
- You call
authenticateWithJWT(), which internally invokes yourcustomAuthclosure - The SDK sends the JWT to CDP’s backend, which validates it against your configured JWKS
- If valid, the user is authenticated and wallets are auto-created based on your configuration
- The
customAuthclosure is called automatically whenever the SDK needs a fresh token
View User Information
Once the end user has signed in, you can read their session and account information.User:
Multi-Factor Authentication
Sensitive actions (signing, sending, spend permissions, delegation) automatically gate on MFA when enabled for the project. You must register an MFA listener viaMFAState —
without one, those actions throw CDPCoreError.mfa(.listenerRequired, _).
The SDK supports two MFA methods:
- TOTP (Time-based One-Time Password): Users enroll using authenticator apps like Google Authenticator or Authy
- SMS: Users receive verification codes via text message to their phone number
Important: Users must be authenticated (signed in) before they can enroll in MFA or perform MFA verification.
Check MFA configuration
MFA enrollment flow
The enrollment flow consists of two steps. For TOTP, enrollment returns anauthUrl and
secret to provision the authenticator app.
MFA verification flow
When performing sensitive operations that require MFA verification, use the verification flow:Create Accounts Manually
If you configured your SDK withoutcreateOnLogin, you can manually create accounts for
authenticated users when needed. This gives you full control over when accounts are
created. All three methods accept an optional idempotencyKey: String.
Sign Messages and Typed Data
End users can sign EVM messages, hashes, and typed data to generate signatures for various onchain applications. All signing operations are MFA-gated when the project enables MFA — see Multi-Factor Authentication.EVM message / hash
EVM transaction (EIP-1559)
EVM typed data (EIP-712)
Solana message / transaction
Solana payloads are passed through as base64.Send an EVM Transaction
We support signing and sending an EVM transaction in a single call. Network enums are available viaSendEvmTransactionNetwork, SendEvmUsdcNetwork, EvmUserOperationNetwork,
SendSolanaTransactionNetwork, and SendSolanaUsdcNetwork.
transfer):
Smart Account Operations
Smart Accounts provide advanced account abstraction features, including user operations and paymaster support.Send user operations
Get user operation status
Send a Solana Transaction
Swaps
useCdpPaymaster and paymasterUrl are mutually exclusive — passing both throws
CDPCoreError.inputValidation.
Spend Permissions
Spend permissions allow Smart Accounts to delegate spending authority to other accounts within specified limits and time periods. This requiresEthereumConfig(enableSpendPermissions: true) and an EVM smart account.
Delegation
Developer-key delegation lets your backend perform certain actions on behalf of the user.getDelegationForAddress,
createDelegationForAddress, and revokeDelegationForAddress.
EIP-7702
Delegate an EOA to a smart-account implementation contract.Error Handling
All SDK errors are cases ofCDPCoreError:
| Case | Meaning |
|---|---|
.notInitialized(String) | start() not called |
.notSignedIn(String) | Operation requires an authenticated user |
.alreadySignedIn(String) | Sign-in attempted while already authenticated |
.accountNotFound(String) | The current user does not own the supplied address |
.inputValidation(String) | Invalid argument (address format, missing field, conflicting options) |
.validation(String) | Server-side validation error |
.mfa(MfaErrorCode, String) | .superseded / .cancelled / .listenerRequired |
.swap(SwapErrorCode, String) | .insufficientLiquidity / .insufficientAllowance / .insufficientBalance / .transactionSimulationFailed |
.customAuth(String) | BYO-auth misconfiguration or JWT failure |
.api(statusCode:errorType:message:correlationId:) | API returned an error |
.network(String) | Transport-level failure |
.internal(String) | Unexpected internal state |
Testing Your Integration
SetuseMock: true to swap in MockWalletsAPIClient, which returns deterministic
responses without making network calls — ideal for SwiftUI previews and unit tests.
WalletsAPIClient
protocol yourself and inject it via the apiClient: parameter on WalletsClient.init.