Skip to main content
The CDP Swift SDK is an embedded-wallets solution for iOS and macOS applications. It provides end-user authentication, account creation, signing, swaps, and transaction broadcasting through the Coinbase Developer Platform. The SDK ships a single library target — CDPCore — exposing an actor-based, async/await API.

Quickstart

This guide will help you get started with CDPCore. 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:
Then add the product to your target:

Gather your CDP Project information

  1. Sign in or create an account on the CDP Portal
  2. 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 a WalletsClient 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).
For OAuth redirects, forward incoming URLs to handleOAuthCode(url:) via .onOpenURL (see OAuth).

Configuration

CDPCoreConfig controls SDK behaviour. Only projectId is required.
For custom platform services (alternative storage, crypto, OAuth), call PlatformRegistry.shared.setPlatformServices(...) before start().

Account configuration

You can configure the SDK to create different types of accounts for new users. Smart Account configuration:
When ethereum.createOnLogin is set to .smart, the SDK will:
  1. Automatically create an EOA (Externally Owned Account) as the owner
  2. Create a Smart Account owned by that EOA
  3. Make both accounts available on the user object
Solana account configuration:
Deferred account creation: Omit 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).
Supported providers via OAuth2ProviderType: .google, .apple, .telegram, plus other configured providers. For manual code exchange (no deep link):
Observe in-progress OAuth state:

Sign-In With Ethereum (SIWE)

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:
  1. 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
  2. Provide a customAuth closure 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, call authenticateWithJWT() to authenticate the user:

How it works

  1. Your user signs in to your identity provider (Auth0, Firebase, Cognito, etc.)
  2. You call authenticateWithJWT(), which internally invokes your customAuth closure
  3. The SDK sends the JWT to CDP’s backend, which validates it against your configured JWKS
  4. If valid, the user is authenticated and wallets are auto-created based on your configuration
  5. The customAuth closure 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.
Existing accounts are exposed on the User:
To end a session:

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 via MFAState — 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 an authUrl 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 without createOnLogin, 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 via SendEvmTransactionNetwork, SendEvmUsdcNetwork, EvmUserOperationNetwork, SendSolanaTransactionNetwork, and SendSolanaUsdcNetwork.
USDC helpers (auto-encodes ERC-20 transfer):

Smart Account Operations

Smart Accounts provide advanced account abstraction features, including user operations and paymaster support.

Send user operations

Get user operation status

Smart-account USDC convenience:

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 requires EthereumConfig(enableSpendPermissions: true) and an EVM smart account.

Delegation

Developer-key delegation lets your backend perform certain actions on behalf of the user.
Address-scoped variants are available: getDelegationForAddress, createDelegationForAddress, and revokeDelegationForAddress.

EIP-7702

Delegate an EOA to a smart-account implementation contract.

Error Handling

All SDK errors are cases of CDPCoreError: Inspect specific cases with pattern matching:

Testing Your Integration

Set useMock: true to swap in MockWalletsAPIClient, which returns deterministic responses without making network calls — ideal for SwiftUI previews and unit tests.
For richer fake responses (programmable per-call), implement the WalletsAPIClient protocol yourself and inject it via the apiClient: parameter on WalletsClient.init.