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

# How It Works

> Understanding the StablePay on/offramp flow

## Choose Your Flow

StablePay supports two directions:

* **Offramp** (Crypto → Fiat) — convert stablecoins to INR
* **Onramp** (Fiat → Crypto) — *Coming soon*

For offramp, there are two options:

| Option              | How it works                                 | Payout                                               |
| ------------------- | -------------------------------------------- | ---------------------------------------------------- |
| **Sell**            | User deposits crypto to their wallet address | Automatic — INR sent after deposit confirms          |
| **Pool Settlement** | Merchant sweeps from a central pool wallet   | Manual — you trigger INR payout after sweep confirms |

Both options follow the same setup steps.

***

## Steps

### 1. Create a User

Create a user with their name and phone number. Each user gets unique deposit addresses.

### 2. Complete KYC

The user must complete identity verification and add a bank account. This is where the INR payout will be sent. See the [KYC Flow guide](/guides/kyc-flow) for details.

### 3. Create a Transaction

Once KYC is verified, create a transaction with `type: sell` or `type: pool_settlement`.

### 4. INR Payout

* **Sell** — payout is triggered automatically once the user's crypto deposit is confirmed on-chain. No additional action needed.
* **Pool Settlement** — after the sweep from your pool wallet is confirmed, you call a second endpoint with the transaction ID to trigger the INR payout.

***

## Sell Flow

```
Create user → Complete KYC → Create transaction (type: sell)
→ User sends crypto → Deposit confirmed → INR sent automatically
```

## Pool Settlement Flow

```
Create user → Complete KYC → Create transaction (type: pool_settlement)
→ USDT swept from pool → Sweep confirmed → You trigger payout → INR sent
```

See the [Pool Settlement guide](/guides/pool-settlement) for the full integration walkthrough.

## Onramp — *Coming soon*

Convert fiat to stablecoins. Contact us for early access.

***

## Under the Hood

### Deposit Detection

Our blockchain listeners monitor deposit addresses across all supported chains:

* **EVM chains** — Poll for ERC-20 Transfer events
* **Tron** — Monitor TRC-20 transfers via TronGrid API
* **Confirmations** — Wait for required block confirmations before processing

### Payout Execution

Once a transaction is ready for payout:

1. Calculate INR amount using live exchange rate
2. Deduct platform fees
3. Initiate bank transfer via IMPS, NEFT, or RTGS
4. Track UTR and update transaction status

### Security

* **PII encryption** — All personally identifiable information encrypted with AES-256-GCM
* **Webhook signatures** — HMAC-SHA256 signed payloads for authenticity verification
* **API authentication** — Bearer tokens with environment isolation (sandbox/production)

***

## Timing Expectations

| Stage                 | Typical Duration |
| --------------------- | ---------------- |
| Deposit Detection     | \< 10 seconds    |
| Polygon Confirmation  | \~1 minute       |
| Ethereum Confirmation | \~3 minutes      |
| Tron Confirmation     | \~1 minute       |
| IMPS Payout           | \< 30 seconds    |

## Next Steps

<CardGroup cols={2}>
  <Card title="KYC Flow" icon="user-check" href="/guides/kyc-flow">
    Understand verification requirements
  </Card>

  <Card title="Transaction Lifecycle" icon="arrows-rotate" href="/guides/transaction-lifecycle">
    See all transaction states and transitions
  </Card>

  <Card title="Pool Settlement" icon="water" href="/guides/pool-settlement">
    Set up centralized liquidity offramp
  </Card>

  <Card title="Webhooks" icon="bell" href="/guides/webhooks">
    Configure real-time notifications
  </Card>
</CardGroup>
