One-time setup
Every purchase
Prerequisites
- Get allowlisted. Contact the Coinbase team to enable your CDP project for App2App. Then register your iOS App Attest identifier (
teamID.bundleID) yourself in CDP Portal, under Payments → Onramp & Offramp → App2App iOS. - Add your redirect host to the domain allowlist. In CDP Portal, under Payments → Onramp & Offramp, add the host of the
redirectUrlyou’ll use. See Security Requirements for supported formats. Requests with aredirectUrlhost that isn’t allowlisted are rejected. - Stand up a backend that holds a CDP API key. Minting the attestation challenge and the purchase challenge both require a CDP API-key JWT; the device only ever sees the challenge that comes back, never the key. See Build your backend.
- Use a physical iOS device. App Attest requires the Secure Enclave, which the iOS Simulator doesn’t have. This applies to sandbox testing too, not just production.
- Use a custom development build, not Expo Go.
@coinbase/cdp-app-attestis a native module; Expo Go can’t load it. Build withexpo run:ios, a custom dev client, or EAS Build. - Enable the App Attest capability in Xcode (requires an Apple Developer Program account) with a deployment target of iOS 14+. See Apple’s DeviceCheck documentation and the App Attest setup guide for background on what this capability does.
- A Google Cloud project with the Play Integrity API enabled, and a service account key created in that same project. Coinbase uses the key to decode your app’s integrity tokens.
- Register your Android app in CDP Portal with your Play package name and the service account key. See Set up Play Integrity below for both steps.
- Distribute through Google Play. Coinbase requires a Play-recognized app on a device that meets device integrity. An internal testing track is enough; builds installed outside Google Play, debug builds, and emulators fail verification.
Set up Play Integrity (Android)
Do this once per Android app, after Coinbase has enabled your CDP project for App2App. Registration is rejected until your project is enabled.Enable the Play Integrity API
initialize({ cloudProjectNumber }) in Start the purchase. Linking the project in Play Console is optional. See Google’s Play Integrity setup guide for background.Create a service account in the same project
coinbase-onramp-play-integrity. You don’t need to grant it any roles or give any users access to it.The service account must belong to the same project whose number your app passes to initialize. Google only lets that project decode your app’s tokens, so a key from any other project fails every purchase.Create a JSON key
.json file. This is the only copy; Google can’t show it again.If key creation is blocked, your organization probably enforces the iam.disableServiceAccountKeyCreation policy. Ask your Google Cloud administrator to allow key creation for this project.Register the app in CDP Portal
- Package name: the application ID of the build you distribute through Google Play, for example
com.example.wallet. Register each variant you ship separately, including any suffixed ID such ascom.example.wallet.beta. A project can register up to 30 packages. - Service account key: the full contents of the
.jsonfile. Coinbase accepts only Google service account keys ("type": "service_account").
Delete your local copy of the key
Rotating or replacing the service account key
Rotating or replacing the service account key
- Create a new JSON key on the same service account (or a new service account in the same project).
- In CDP Portal, remove the package, then register it again with the new key. Android purchases from that package fail between the two steps, so do this during low traffic.
- After a purchase succeeds with the new key, delete the old key in the Google Cloud console.
The four API routes
Everything in this guide comes down to four HTTP calls. The two challenge-mint calls need a CDP API key and run on your backend; the other two are unauthenticated and can be called directly from the device, or proxied through your backend for a single base URL (see Build your backend).1. Mint attestation challenge
1. Mint attestation challenge
- Auth: CDP API key JWT, from your backend
- Called: once per install, before registering the device. iOS only
2. Register the device key
2. Register the device key
- Auth: none
- Called: once per install, right after the device attests the challenge above. iOS only
3. Mint purchase challenge
3. Mint purchase challenge
- Auth: CDP API key JWT, from your backend
- Called: once per purchase, before starting the purchase
4. Create the session
4. Create the session
- Auth: none
- Called: once per purchase, right after the device signs the challenge above
ios or android.One-time setup
Do these four things once, when you build the integration. None of them repeat per purchase.1. Install dependencies
@coinbase/cdp-app-attestis required. It’s the native module that drivesDCAppAttestServicedirectly and is what this guide uses for the App Attest ceremony in Register each device and Start the purchase.@coinbase/cdp-react-nativeis optional, used only for itscanOpenCoinbaseOnramp()andhandleOnrampReturn()helpers (Detect the Coinbase app and Handle the return). This guide does not use itsopenCoinbaseOnramp()function.- If you’re building a native iOS app without React Native, call
DCAppAttestServicedirectly wherever this guide shows a@coinbase/cdp-app-attestcall, andcanOpenURLdirectly for detection — the request/response shapes are identical.
2. Configure your iOS project
Enable the App Attest entitlement
Info.plist/entitlements:development for local debug builds if you want Apple’s sandbox App Attest environment; see Sandbox testing for how this interacts with partnerUserRef.Declare both Coinbase onramp URL schemes
Info.plist so canOpenCoinbaseOnramp() can detect the installed Coinbase app:canOpenURL, or the call always returns false. Declare both schemes:com.coinbase.cdp.onramp.v2is registered by newer Coinbase app builds that support the current App2App input contract (purchaseAmount,paymentMethod).com.coinbase.cdp.onrampis the legacy scheme, still registered by older Coinbase app builds.canOpenCoinbaseOnramp()treats either as “supported” so users on an older Coinbase app build aren’t incorrectly told App2App is unavailable.
canOpenURL unless your manifest declares the scheme in <queries>. Add both schemes to AndroidManifest.xml (with Expo, through a config plugin):
com.coinbase.cdp.onramp.v2. Declaring both lets canOpenCoinbaseOnramp() probe the same schemes on both platforms.
3. Build your backend
Add two routes, one per authenticated call. Each signs a CDP API key JWT and forwards to CDP:4. Register each device
iOS only. Android has no device registration; skip to Every purchase. Do this once per install, before the device’s first purchase. Persist the registration locally, scoped to your CDP project ID.attest() and createAssertion() (used here and in Start the purchase) both expect standard base64 input, but CDP mints challenges as base64url (unpadded). Convert before signing:
Where does this call actually go?
Where does this call actually go?
https://api.cdp.coinbase.com/platform/v2/onramp/mobile/attestation/registrations), or to your backend’s pass-through proxy if you built one. Either way, it’s unauthenticated: no Authorization header, no projectId or keyId path params. keyId travels only in the body — App Attest key IDs are standard base64 and often contain /, which breaks path routing at the edge. See The four API routes above for the exact request and response.Why clear the registration on any failure, even a network error?
Why clear the registration on any failure, even a network error?
attestKey is a one-time operation per key: if registration fails after attest() succeeds, the key’s attestation slot is already consumed. Always clear the local registration on failure (as shown above) so the next attempt provisions a fresh key, rather than retrying attest() on the same one.attest() calls DCAppAttestService.attestKey under the hood with clientDataHash = SHA-256(base64url_decode(challenge)). If you’re calling DCAppAttestService directly instead, apply that same decode-then-hash order; hashing the base64url string directly fails verification.
Every purchase
This flow repeats for every purchase a signed-in user makes. It assumes one-time setup is already done.1. Detect the Coinbase app
Before showing or enabling your “Pay with Coinbase” button, check whether the installed Coinbase app supports App2App:canOpenCoinbaseOnramp() probes both schemes declared in Configure your iOS project (the <queries> entries on Android) and resolves false if neither is available or if either probe throws. Re-run this check whenever your app returns to the foreground, in case the user installed or removed the Coinbase app while your app was backgrounded.
Not using React Native? Probe both schemes with canOpenURL directly and treat either true as supported:
2. Start the purchase
Call this when the user taps your “Pay with Coinbase” button:initialize makes a network call, so don’t repeat it for every purchase:
order is the body your backend forwards to /v2/onramp/mobile/sessions/challenges. There’s no projectId field: the challenge is minted under your backend’s CDP API key JWT, and that JWT is what identifies the project.
Order parameters & pricing reference
Order parameters & pricing reference
- Buy Config: countries and payment methods
- Buy Options: assets, networks, and limits
- Buy Quote: an actual fee breakdown
challengeexpires 5 minutes after it’s minted. If the session call returnsstale_attestation, mint a fresh purchase challenge and retry with a new assertion (on iOS, keep the same registered device key).- The session call is idempotent on the challenge: if you don’t receive a response (for example, due to a dropped connection), retry it. Retrying an already-attested challenge returns the same URL rather than an error.
- The returned
onrampUrl’s session token expires 15 minutes after it’s issued.
What if the attestation key becomes invalid? (iOS)
What if the attestation key becomes invalid? (iOS)
/v2/onramp/mobile/sessions rejects the assertion with an invalid-key error, self-heal by clearing the registration and re-running Register each device before retrying the purchase once:isAttestationKeyError against the error message (phrases like “invalid key,” “key not found,” or “assertion could not be verified”). This mirrors the retry pattern in the reference demo app.3. Handle the return
The Coinbase app redirects back to yourredirectUrl as a universal link with one of three outcomes. There’s no reason code on any of them; the query parameters below are everything you get:
@coinbase/cdp-react-native, call handleOnrampReturn in your deep-link handler every time your app receives this redirect:
handshakeNonce-based security handshake that handleOnrampReturn will eventually perform. Adding the call now means your app automatically participates once the backend starts requiring it, with no further code changes on your end.
handshakeNonceis only included onsuccess.errorandcancelledcarry no detail about what went wrong or how far the user got. If you need to distinguish “not eligible” from “transaction failed,” you can’t do it from the redirect alone.- If the user isn’t already signed in to Coinbase, they’ll sign in or create an account (and complete KYC if they’re new) before the purchase continues, all inside the Coinbase app, with no separate step needed from you.
4. Confirm the transaction
- Follow the Onramp & Offramp Webhooks guide to create a webhook subscription for
onramp.transaction.success(and.created/.updated/.failedif you want the intermediate states). - Match incoming events to your user with
partnerUserRef; it’s included in every payload. - Treat a transaction as settled only when the event is
onramp.transaction.success(or, if you’re inspecting the payload directly,statusisONRAMP_TRANSACTION_STATUS_SUCCESS). - App2App transactions include
isAppToApp: true, so you can distinguish them from other purchase flows if needed.
partnerUserRef you sent when starting the purchase:
- Match transactions using
partnerUserRefplustxHash, purchase currency, and amount. The redirect’stransactionIddoesn’t match thetransactionIdreturned by this endpoint: they’re generated by different systems for the same purchase, so don’t use them to join records, even though the redirect’s value now looks like a real ID on a live purchase rather than a placeholder. - Sandbox (dry-run) sessions are the exception to both of the above; see Sandbox testing.
Sandbox testing
You can exercise the full flow (registration, challenge, session, handoff, and redirect) without moving real funds. There’s no way to skip attestation just to preview the UI: every purchase, sandbox or live, runs the real attestation ceremony on a physical device — the iOS Simulator can’t attest at all, since it has no Secure Enclave. Which path applies depends on the build you’re testing with:partnerUserRef like sandbox-user-1234 is what puts the session into sandbox mode; there’s no separate sandbox flag, endpoint, or allowlist.
What actually happens in sandbox mode?
What actually happens in sandbox mode?
transactionId generated for that sandbox purchase only. But no webhook fires and no row appears in the transactions API — the redirect is the only confirmation signal you get in sandbox. See Confirm the transaction.- Keep the
sandbox-prefix until you’re ready to move real funds; it’s independent of which App Attest environment you’re using. - Android has no separate test environment for Play Integrity. Install your app from a Google Play track (internal testing works) on a physical device, and use the
sandbox-prefix to dry-run. Builds installed outside Google Play, debug builds, and emulators fail verification even in sandbox mode.
Errors
What to read next
- FAQ: Common questions from partners integrating App2App
- Onramp & Offramp Webhooks: Full webhook setup and payload reference
- Security Requirements: Domain allowlist requirements for your redirect URL
- onramp-v2-mobile-demo: Full reference implementation of the client and backend pieces in this guide