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

# Invite Codes

> Handle Mainnet invite mode in your frontend: sign users in with an invite code and let them share their own.

In Mainnet **invite mode**, a wallet without Mainnet access gets it by redeeming an invite code at sign-in; wallets with access can mint codes to share. Invite mode is per-deployment: branch on the refusal code, don't hard-code it.

## Surface Map

| Surface | Use |
| - | - |
| REST | `POST /api/v1/auth/verify` (`inviteCode` in the body), `POST /api/v1/invite-codes/requests`, `GET /api/v1/invite-codes` |
| TypeScript SDK | `sdk.login(clientId, { inviteCode })`, `sdk.auth.verifySignature(..., inviteCode)`, `sdk.auth.requestInviteCodes()`, `sdk.auth.listInviteCodes()`, `INVITE_ERROR_CODES` from `@0xmonaco/types` |
| React SDK | `useAuth()`: `login({ inviteCode })`, `requestInviteCodes()`, `listInviteCodes()` |
| WebSocket | None |
| gRPC | `AuthService.Verify` (`invite_code`), `AuthService.RequestInviteCodes`, `AuthService.ListInviteCodes` |

## Access Rules

* **Access is lasting.** A wallet that redeemed a code, or signed in while invite mode was off, never needs one again; only deactivation blocks it. Any wallet without access needs a code, existing accounts included.
* **A code is redeemed only when needed.** A wallet with access: code ignored. A wallet without access while invite mode is off: not redeemed, but still checked, so it can get `429` (cooldown) or `503`.
* **A code redeems once**, for the first wallet to sign in with it.

## Sign-In With a Code

Sign in without a code first; on `INVITE_CODE_REQUIRED`, ask for a code and sign in again. React's `useAuth().login` takes the same `inviteCode` option and throws the same `APIError`.

```typescript theme={null}
import { APIError } from "@0xmonaco/core";
import { INVITE_ERROR_CODES } from "@0xmonaco/types";

const INVITE_CODE_FORMAT = /^[A-Za-z0-9]{10}$/;

async function signIn(inviteCode?: string) {
  try {
    return { status: "signed-in", auth: await sdk.login(clientId, inviteCode ? { inviteCode } : undefined) };
  } catch (error) {
    if (!(error instanceof APIError)) throw error;
    if (error.serverCode === INVITE_ERROR_CODES.INVITE_CODE_REQUIRED) return { status: "needs-code" };
    if (error.serverCode === INVITE_ERROR_CODES.INVITE_CODE_INVALID) return { status: "code-rejected" };
    if (error.serverCode === INVITE_ERROR_CODES.ACCOUNT_DEACTIVATED) return { status: "deactivated" };
    if (error.statusCode === 429) return { status: "cooldown", retryAfter: error.retryAfter };
    if (error.statusCode === 503) return { status: "retry-later" };
    throw error;
  }
}

// After "needs-code": validate the format first
if (INVITE_CODE_FORMAT.test(codeInput)) await signIn(codeInput);
```

Codes are exactly 10 case-sensitive letters or digits. Check the format first and never change the case: a malformed code is refused as `INVITE_CODE_INVALID` and counts toward the cooldown.

Each `login` is a new wallet prompt. If the user arrived with a code (say, from an `?invite=` link your app defines), pass it on the first sign-in; on `429` or `503` from that attempt, retry without the code before showing the refusal.

### Refusals to Handle

| Outcome | Meaning | What to show |
| - | - | - |
| `403` `INVITE_CODE_REQUIRED` | No access, no code passed | Code entry |
| `403` `INVITE_CODE_INVALID` | Wrong, malformed, redeemed, revoked, or unused with a deactivated issuer (deliberately indistinguishable) | "That code didn't work" |
| `429` | Cooldown after repeated failures from this wallet or client address | Wait `APIError.retryAfter` seconds (also `details.retryAfter` in the body) |
| `503` | Could not validate right now; not a verdict | Retry shortly |
| `403` `ACCOUNT_DEACTIVATED` | Account deactivated | Blocked-account message; no code entry |

## Share Invite Codes

Allowance: one initial code, plus one per 250,000 USDC of Mainnet volume.

| Call | Behavior |
| - | - |
| `listInviteCodes()` | Reads allowance and minted codes, newest first. Never mints: safe on page load and for polling; recovers a code whose mint response was lost. |
| `requestInviteCodes()` | Mints one code, using a slot; only on user request. No `code` once the allowance is used. Needs active Mainnet access. |

```typescript theme={null}
const { availableCodes, totalAllowance, mainnetVolumeUsd, codes } = await sdk.auth.listInviteCodes();
const shareable = codes.filter((entry) => entry.status === "issued" && entry.code);

async function onMintClick() {
  if (availableCodes === 0) return;
  const { code } = await sdk.auth.requestInviteCodes();
  if (code) showCopyable(code);
}
```

* `status`: `issued`, `redeemed`, or `revoked`. Only `issued` entries carry `code`; others show `milestone` and dates.
* `milestone` `0` is the initial code; N is the Nth 250,000 USDC. A revoked code never refunds its slot.
* `mainnetVolumeUsd` is a decimal string; don't parse it as a float for comparisons.
* Both calls refuse delegated agent sessions with `403` (owner wallet only) and return `503` when temporarily unavailable; retry.

Full shapes and errors: [Mainnet Invite Codes](https://docs.0xmonaco.com/sdk/typescript/auth.md#mainnet-invite-codes).

## Handling Codes Safely

* Until redeemed, a code is a bearer secret: never log it or send it to analytics or error reports; don't store codes beyond the session.
* Keep codes out of URLs sent to third parties (referrer headers, link previews); for invite links, read the code on arrival and drop it from the address bar.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.