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

# WebView Communication

> Understand how your mini app communicates with the Lemon Cash mobile app

## Overview

The Mini App SDK enables communication between your web-based mini app and the Lemon Cash mobile application through React Native WebView technology. This communication bridge allows your mini app to request wallet authentication, deposit and withdrawal transactions, as well as smart contract interactions.

## How it works

The communication flow follows a message-based architecture:

<Steps>
  <Step title="Mini app sends message">
    Your mini app sends a message to the native app using `window.ReactNativeWebView.postMessage()`.

    ```typescript theme={null}
    // Example: Sending authentication request
    window.ReactNativeWebView.postMessage(JSON.stringify({
      action: 'AUTHENTICATE',
      nonce: 'l3m0nc45h'
    }));
    ```
  </Step>

  <Step title="Lemon Cash processes the request">
    The Lemon Cash mobile app receives the message and processes the request. It will prompt the user to confirm the action before executing it.
  </Step>

  <Step title="Lemon Cash responds">
    The Lemon Cash mobile app sends a response back to your mini app using `webViewRef.current.postMessage()`.

    ```typescript theme={null}
    // Example: Authentication response
    webViewRef.current.postMessage(JSON.stringify({
      action: 'AUTHENTICATE_RESPONSE',
      data: {
        wallet: '0x...',
        signature: '0x...',
        message: '...'
      }
    }));
    ```
  </Step>

  <Step title="Mini app receives">
    Your mini app receives the response through event listeners and updates its state accordingly.
  </Step>
</Steps>

## Environment Detection

The SDK provides a [isWebView](/functions/is-webview) hook to detect if your app is running inside the Lemon Cash WebView:

```typescript theme={null}
import { isWebView } from '@lemoncash/mini-app-sdk';

function MyMiniApp() {  
  if (!isWebView()) {
    return <div>This app only works inside Lemon Cash</div>;
  }
  
  return <div>Welcome to your mini app!</div>;
}
```
