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

# Installation & Setup

> Set up the Payment SDK in your application

## Prerequisites

* A Grain merchant account with a **Merchant ID**
* A server-side **API key** for creating payment sessions
* Node.js 18+ (for Next.js applications)

## Get Your Credentials

<Steps>
  <Step title="Get your Merchant ID">
    Log in to the [Grain Dashboard](https://dashboard.grain.inc) and navigate to **Settings > API Keys**. Copy your **Merchant ID** — this is used to initialize the client-side SDK.
  </Step>

  <Step title="Get your API key">
    From the same page, copy your **API Key**. This is your server-side secret used to create payment sessions.

    <Warning>
      Never expose your API key in client-side code. It should only be used in server-side route handlers or backend services.
    </Warning>
  </Step>
</Steps>

## Configure Environment Variables

Add the following to your `.env` file:

```bash theme={null}
# Required
NEXT_PUBLIC_CUBEPAY_MERCHANT_ID=your-merchant-id    # Client-side: SDK initialization
CUBEPAY_API_KEY=your-api-key                         # Server-side: session creation

# Optional
CUBEPAY_API_HOST=https://api.pay.grain.inc           # API host (defaults to production)
```

## Add the SDK Mount Point

The Payment SDK renders its payment modal inside a dedicated DOM element. Add this to your root layout:

```tsx theme={null}
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <div id="cubepay-sdk-root" className="cubepay-sdk-root" />
      </body>
    </html>
  );
}
```

<Info>
  The SDK creates a **Shadow DOM** inside this element, so its styles are fully isolated from your application. No CSS conflicts.
</Info>

## Load the SDK Bundle

The client-side SDK is distributed as a UMD bundle. Place it in your public directory:

```
public/
  vendor/
    cubist-pay-client-sdk.umd.js
```

The SDK service loads this script lazily on first use — no manual script tags needed.

## Environment Comparison

| Feature             | Sandbox                     | Production                |
| ------------------- | --------------------------- | ------------------------- |
| Blockchain networks | Testnets (Sepolia)          | Mainnets (Ethereum, Base) |
| Real funds          | No                          | Yes                       |
| Webhooks            | Supported                   | Supported                 |
| Settlement          | Simulated                   | Real on-chain settlement  |
| API host            | `api.sandbox.pay.grain.inc` | `api.pay.grain.inc`       |

## Next Steps

Proceed to [Initialize the SDK](/payment-sdk/integration-guide/initialize-sdk) to set up the SDK service and process your first payment.
