> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Quickstart

> Let users withdraw stablecoins to their bank account from your Android app

In this guide, you will add a withdrawal flow to a Jetpack Compose app with the `CrossmintEmbeddedOfframp` component and run a withdrawal in the Staging environment. You will:

* Create an offramp session on your server for the user and the wallet they withdraw from
* Render `CrossmintEmbeddedOfframp` with the session and a payer that signs with the user's wallet
* Handle the component's events
* Test a withdrawal on staging

The component runs the whole withdrawal inside your app: the user picks, adds, renames or removes a bank account, enters an amount, verifies their identity if the order needs it, reviews the quote and approves the deposit from their wallet.

<Snippet file="offramp-embedded-flow.mdx" />

## Prerequisites

* **Backend**: one server endpoint that creates the session, such as the Express route in this guide.
* **Android**: Android 7.0 (API level 24) or later, Jetpack Compose, and an Android System WebView that supports `WEB_MESSAGE_LISTENER`. Host the component in an activity that provides an `ActivityResultRegistryOwner`, such as a `ComponentActivity`.

<Snippet file="offramp-embedded-prereqs.mdx" />

* **Wallet**: an EVM or Solana wallet that your app can sign and broadcast transactions with, owned by or linked to `userId:<USER_ID>`. To use a wallet that Crossmint did not create, link it to the user with [Link External Wallet to User](https://docs.crossmint.com/api-reference/users/link-wallet.md) before you create the session. The session takes only `userId:` locators, so email and phone locators do not work. This guide uses `base-sepolia`.
* **USDC**: testnet USDC in the wallet, from the [Circle faucet](https://faucet.circle.com/).
* **Permissions**: declare `android.permission.INTERNET` and `android.permission.CAMERA` in `AndroidManifest.xml`. Identity verification captures documents with the camera. The component asks for the runtime camera permission when the page first needs it. Without the manifest entry, Android denies the camera and only document upload works.

Add the Crossmint offramp module, version 1.5.0 or later, to your app's `build.gradle.kts`. It is published on Maven Central:

```kotlin build.gradle.kts theme={null}
dependencies {
    implementation("com.crossmint:sdk-offramp:1.5.2")
}
```

### 1. Create the session on your server

A session lets one user make one withdrawal from one wallet. Your backend makes one call, [Create Offramp Session](https://docs.crossmint.com/offramp/api-reference/create-offramp-session.md), and the component runs every other step with Crossmint:

<Snippet file="offramp-embedded-where-it-runs.mdx" />

<Snippet file="offramp-embedded-session-backend.mdx" />

<Snippet file="offramp-embedded-session-fields.mdx" />

<Snippet file="offramp-embedded-https-backend.mdx" />

### 2. Render the offramp component

Create a composable that asks your backend for a session and renders `CrossmintEmbeddedOfframp`. The `payer` signs and sends the deposit with your wallet code, which the screen takes as `sendDeposit`. With `fill = true`, the offramp fills the space its container gives it and scrolls inside itself:

```kotlin WithdrawScreen.kt theme={null}
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.crossmint.kotlin.offramp.CrossmintEmbeddedOfframp
import com.crossmint.kotlin.offramp.EmbeddedOfframpCredentials
import com.crossmint.kotlin.offramp.EmbeddedOfframpPayer
import com.crossmint.kotlin.offramp.OfframpTransaction
import com.crossmint.kotlin.offramp.OfframpTransactionResult
import java.net.HttpURLConnection
import java.net.URL
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONObject

// Replace with your client-side API key and your backend URL.
const val CROSSMINT_API_KEY = "YOUR_CLIENT_API_KEY"
const val SESSION_URL = "https://YOUR_BACKEND_URL/api/offramp-session"

@Composable
fun WithdrawScreen(
    userId: String,
    email: String,
    walletAddress: String,
    chain: String,
    sendDeposit: suspend (OfframpTransaction) -> OfframpTransactionResult,
) {
    var credentials by remember { mutableStateOf<EmbeddedOfframpCredentials?>(null) }
    var isLoading by remember { mutableStateOf(false) }
    var isSigning by remember { mutableStateOf(false) }
    val scope = rememberCoroutineScope()
    val session = credentials

    if (session == null) {
        Button(
            enabled = !isLoading,
            onClick = {
                scope.launch {
                    isLoading = true
                    try {
                        credentials = createOfframpSession(userId, email, walletAddress, chain)
                    } catch (e: Exception) {
                        Log.e("Withdraw", "Failed to create the offramp session", e)
                    } finally {
                        isLoading = false
                    }
                }
            },
        ) {
            Text(if (isLoading) "Starting..." else "Withdraw to bank")
        }
    } else {
        Column(Modifier.fillMaxSize()) {
            TextButton(onClick = { credentials = null }, enabled = !isSigning) { Text("Close") }
            CrossmintEmbeddedOfframp(
                apiKey = CROSSMINT_API_KEY,
                credentials = session,
                payer = EmbeddedOfframpPayer(
                    signAndSendTransaction = { transaction ->
                        isSigning = true
                        try {
                            sendDeposit(transaction)
                        } finally {
                            isSigning = false
                        }
                    },
                ),
                modifier = Modifier.weight(1f),
                fill = true,
                onStatusChange = { Log.d("Withdraw", "Offramp status: ${it.status} ${it.orderId}") },
                onComplete = { Log.d("Withdraw", "Withdrawal sent: ${it.orderId} ${it.txId}") },
                onCancel = { credentials = null },
                onError = { Log.e("Withdraw", "Offramp error: ${it.code} ${it.retriable} ${it.message}") },
            )
        }
    }
}

private suspend fun createOfframpSession(
    userId: String,
    email: String,
    walletAddress: String,
    chain: String,
): EmbeddedOfframpCredentials = withContext(Dispatchers.IO) {
    val connection = URL(SESSION_URL).openConnection() as HttpURLConnection
    try {
        connection.requestMethod = "POST"
        connection.doOutput = true
        connection.setRequestProperty("Content-Type", "application/json")
        val body = JSONObject()
            .put("userId", userId)
            .put("receiptEmail", email)
            .put("walletAddress", walletAddress)
            .put("chain", chain)
        connection.outputStream.use { it.write(body.toString().toByteArray()) }
        check(connection.responseCode == 200) {
            "Create Offramp Session failed (${connection.responseCode})"
        }
        val json = JSONObject(connection.inputStream.bufferedReader().use { it.readText() })
        EmbeddedOfframpCredentials(json.getString("sessionId"), json.getString("clientSecret"))
    } finally {
        connection.disconnect()
    }
}
```

Render `WithdrawScreen` with the signed-in user's ID and email, the address and chain of their wallet, and your wallet code as `sendDeposit`. The component calls `sendDeposit` with the deposit to send:

* **`serializedTransaction`**: a serialized transaction on EVM chains, or a base58 legacy transaction with `feePayer` and `recentBlockhash` set on Solana. Sign and broadcast it unchanged.
* **`chain`** and **`payerAddress`**: the chain and wallet the deposit was prepared for. Refuse to send from a wallet that does not match. See [Refuse a mismatched wallet](https://docs.crossmint.com/offramp/guides/handle-events-and-errors.md#refuse-a-mismatched-wallet).

Return one of these results:

* **`OfframpTransactionResult.Sent(txId)`**: the transaction was broadcast. `txId` is the transaction hash, or the signature on Solana.
* **`OfframpTransactionResult.Rejected`**: the user declined and nothing was broadcast. The component offers the withdrawal again with a new rate.
* **`OfframpTransactionResult.Unknown`**: the transaction may have been broadcast. The component waits for the deposit instead of letting the user send it twice. A thrown exception counts as `Unknown`.

**Close** stays disabled while `sendDeposit` runs, because the component has to stay on screen to pass your wallet's answer back to the offramp.

Without `fill`, the component takes the height of the page, at least 650px plus padding, and grows when a screen needs more. See [Sizing](https://docs.crossmint.com/offramp/guides/ui-customization.md#sizing).

### 3. Handle the events

<Snippet file="offramp-embedded-handle-events.mdx" />

### 4. Test on staging

<Snippet file="offramp-embedded-test-on-staging.mdx" />

## Prove Wallet Ownership

An order can need proof that the user owns the wallet. To let the component ask for it, pass `signMessage` to `EmbeddedOfframpPayer`. The component calls it with a Crossmint sign-in challenge for `payerAddress`. Return `OfframpMessageResult.Signed(signature)` with the EIP-191 `personal_sign` signature as a 0x-prefixed hex string on EVM chains, or the base64 encoding of the 64-byte ed25519 signature over the UTF-8 message on Solana. Return `OfframpMessageResult.Rejected` when the user declines. Adding or removing `signMessage` reloads the offramp.

Without `signMessage`, the component stops with the `wallet-ownership-required` error. Link the wallet again with an ownership `proof`, then create a new session. For Solana deposits, see [Offramp Orders on Solana](https://docs.crossmint.com/offramp/guides/sign-deposit-solana.md).

## Troubleshooting

<Snippet file="offramp-embedded-troubleshooting.mdx" />

> [accordion] The component renders nothing
>
> The component needs an Android System WebView that supports `WEB_MESSAGE_LISTENER`. On an older WebView, `onError` reports a non-retriable error and the component renders nothing. Ask the user to update Android System WebView from the Play Store.

## Launching in Production

<Snippet file="offramp-embedded-launch.mdx" />

## Learn More

> [card] [Handle Offramp Events and Errors](https://docs.crossmint.com/offramp/guides/handle-events-and-errors.md)
>
> What each status and error reason means

> [card] [Embedded Offramp UI Customization](https://docs.crossmint.com/offramp/guides/ui-customization.md)
>
> Style the offramp screens with your appearance settings
