---
id: I0019
title: "Supabase wallet sign-in"
url: https://carbium.sh/library/integrate/supabase-wallet-sign-in
collection: Integrations
category: Identity and auth
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Supabase wallet sign-in

Supabase Auth verifies the wallet signature and issues the session. A server check then reads the wallet's token holdings from Carbium RPC and prints an access decision as JSON, ready to store beside the user and read in a row-level security policy.

## Who does what

Wallet sign-in is two jobs with two owners. Supabase Auth proves that the person holds the private key for an address and hands the browser a session. Carbium answers the question Supabase leaves open: what that address holds on mainnet right now.

| Step | What happens |
|---|---|
| Browser | The wallet signs a sign-in message and `signInWithWeb3` sends it to Supabase. |
| Supabase Auth | Checks the signature, finds or creates the user, returns a session. |
| Your server | Takes the address from the verified user and runs `main.ts`. |
| Carbium RPC | Answers `getBalance` and `getTokenAccountsByOwner` for that address. |
| Your database | Stores the decision in a row keyed by the Supabase user id. |

Nothing in the flow sends a transaction. The only signature is the sign-in message, made inside the wallet.

## The Supabase side: the sign-in call

In the Supabase dashboard, turn on the Web3 wallet provider under Authentication. In the browser the call is `supabase.auth.signInWithWeb3({ chain: "solana", statement })`. The wallet shows the user a Sign-In With Solana message with your domain and the statement text, and the user approves it. Supabase checks the signature against the address and returns a session like any other provider.

Supabase does the signature check, so the server code never touches a signature, a message or a private key. Your server trusts an address only when it comes from a session Supabase issued: validate the access token with `getUser` on every call, and ignore any address a client puts in a request body.

Where the address sits on the user object depends on your project and library version. Log the user once after a test sign-in, find the web3 identity, and read the address there. The sample takes the address as an argument so it does not depend on that shape.

## The Solana side: holdings of one mint

Carbium RPC lives at [services.carbium.sh](https://carbium.sh/docs#endpoints). The check runs two reads together under `Promise.allSettled`, so one failure does not hide the other.

`getBalance` returns lamports, and 1 SOL is 1,000,000,000 lamports. `getTokenAccountsByOwner` with a mint filter and `jsonParsed` encoding lists every token account the wallet holds for that mint, and the code adds their raw amounts, since a wallet can own more than one token account for one mint. A raw amount is an integer in the mint's smallest unit: 5 USDC, which has 6 decimals, is 5000000 in `GATE_MIN_RAW`.

## The check

Install with `npm install @solana/kit@8.6.0` and set `"type": "module"` in `package.json`. Node 24 strips the types on load. `CARBIUM_KEY` and `GATE_MINT` are required, the wallet address is the first argument, and `CARBIUM_RPC_URL` and `GATE_MIN_RAW` (default 1) are optional.

`main.ts` (run: `node main.ts`)

```ts
// I0019 · Supabase wallet sign-in
// https://carbium.sh/library/integrate/supabase-wallet-sign-in
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  isAddress,
} from "@solana/kit";

const key = process.env.CARBIUM_KEY;
const mint = process.env.GATE_MINT;
const wallet = process.argv[2];
if (!key || !mint || !wallet) {
  console.error("Set CARBIUM_KEY and GATE_MINT, and pass the wallet address as the first argument.");
  process.exit(1);
}
if (!isAddress(wallet) || !isAddress(mint)) {
  console.error("The wallet and GATE_MINT must be base58 Solana addresses.");
  process.exit(1);
}
const minRaw = BigInt(process.env.GATE_MIN_RAW ?? "1"); // raw units: amount * 10^decimals

const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({
    url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
    headers: { "x-api-key": key },
  }),
);
const owner = address(wallet);
const abortSignal = () => AbortSignal.timeout(8_000);

// No commitment named: @solana/kit fills in "confirmed".
const [balance, tokens] = await Promise.allSettled([
  rpc.getBalance(owner).send({ abortSignal: abortSignal() }),
  rpc
    .getTokenAccountsByOwner(owner, { mint: address(mint) }, { encoding: "jsonParsed" })
    .send({ abortSignal: abortSignal() }),
]);
for (const [name, r] of [
  ["getBalance", balance],
  ["getTokenAccountsByOwner", tokens],
] as const) {
  if (r.status === "rejected") console.error(`${name} failed:`, r.reason instanceof Error ? r.reason.message : r.reason);
}

type Parsed = { account: { data: { parsed: { info: { tokenAmount: { amount: string } } } } } };
let held: bigint | null = null;
let accounts: number | null = null;
let slot: string | null = null;
if (tokens.status === "fulfilled") {
  const list = tokens.value.value as unknown as Parsed[];
  accounts = list.length;
  slot = tokens.value.context.slot.toString();
  // A wallet can own several token accounts for one mint: add them up.
  held = list.reduce((sum, a) => sum + BigInt(a.account.data.parsed.info.tokenAmount.amount), 0n);
}

console.log(
  JSON.stringify(
    {
      wallet,
      allowed: held !== null && held >= minRaw, // closed when the read failed
      heldRaw: held?.toString() ?? null,
      tokenAccounts: accounts,
      lamports: balance.status === "fulfilled" ? balance.value.value.toString() : null,
      slot,
      checkedAt: new Date().toISOString(),
    },
    null,
    2,
  ),
);
```

Run `node main.ts` with the address after it. It prints one JSON object with `wallet`, `allowed`, `heldRaw`, `tokenAccounts`, `lamports`, `slot` and `checkedAt`. The `slot` is the one the token read came from. A failed call prints its name and message to stderr and leaves its field null. A failed token read makes `allowed` false, so the gate stays closed when the answer is unknown.

## Where the check runs and what it writes

Run the check where your secrets live: your Node API or a Supabase Edge Function. Edge Functions run on Deno, which imports npm packages with an `npm:` prefix, so the two reads move over with a changed import line and `Deno.env.get` for the key. Store the key with `supabase secrets set CARBIUM_KEY=...`. Build the client once at module scope and reuse it for every request.

1. The browser signs in, then calls your function with its session token.
2. The function validates the token with Supabase and reads the address from the user's web3 identity.
3. It runs the two reads and upserts `wallet_access(user_id, wallet, allowed, held_raw, checked_at)` with the service-role client.
4. A policy on your tables checks the row, for example `exists (select 1 from wallet_access w where w.user_id = auth.uid() and w.allowed)`.

Give `wallet_access` a select policy for the owner and no insert or update policy, so only the service role writes it. Holdings change after sign-in, so call the function again when `checked_at` is older than you accept.

## What it costs against your limits

Limits are [per account](https://carbium.sh/docs#limits), so all keys share one budget. A sign-in check makes two calls, so a launch that sends many sign-ins in the same second can get 429 with a `retry-after` hint.

The sample skips [`getSignaturesForAddress`](https://carbium.sh/docs#rpc). An activity condition such as "transacted in the last 30 days" would add that call: 50 cells, 0.24 req/s on Free and 1.2 on Dev. Its address index keeps up to 30 days, and an empty page past that shows the index's age limit while the address may have older transactions.

## Where it ends

- A signature proves control of a key at sign-in. It says nothing about who the person is, and a person who signs in with two wallets becomes two users.
- The decision is a snapshot. Tokens can move one second after the read, so re-check on a schedule or on the actions that matter.
- It reads one mint. Gating on a collection NFT means reading metadata accounts, which the sample skips; [Bulk NFT metadata reader](https://carbium.sh/library/howsolana/bulk-nft-metadata-reader) reads them.
- It does not read whether a token account is frozen.
- Linking a wallet to an existing email user, mobile wallet flows and Supabase's own provider settings belong to Supabase's documentation.
- A wallet app must support signing a message for `signInWithWeb3` to work, and support varies by wallet app.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The check exits with `Set CARBIUM_KEY and GATE_MINT, and pass the wallet address as the first argument.` | Export the variables and pass the address after `node main.ts`. In an Edge Function, set them as secrets and redeploy. |
| `getTokenAccountsByOwner failed:` shows an HTTP 401 and every wallet gets `allowed: false`. | An unknown key gets [401 at the door](https://carbium.sh/docs#errors). Attach the whole key in `x-api-key`, and check that the secret reached the function you deployed. |
| A wallet that holds the token gets `allowed: false` and `tokenAccounts` 0. | `GATE_MINT` is the wrong mint, or the address came from a different wallet than the one holding the token. Compare the mint and the address with the wallet app. |
| `GATE_MIN_RAW=5` lets in a wallet that holds a tiny fraction of one token. | `GATE_MIN_RAW` is in raw units. Multiply the amount by 10 to the power of the mint's decimals. |
| Many sign-ins at once show 429 in the stderr lines. | Calls over their [rate limit](https://carbium.sh/docs#limits) get 429 with a `retry-after` hint. Queue the checks and retry after the hinted wait instead of denying. |
| A new user signs in and your policy returns no rows. | The row is written after sign-in. Have the client wait for the function's answer before it queries the gated tables. |

## Questions

### Does Supabase check the signature or do I?

Supabase Auth checks it inside `signInWithWeb3`. Your code never sees a signature, and the server check starts from the address.

### Why read holdings on a server?

The Carbium key would sit in the page for anyone to copy, and a result computed in the browser can be edited by the user. On a server both stay yours.

### Can a WebSocket revoke access when the tokens move?

It can, but a scheduled re-check is simpler. A watcher would use [`logsSubscribe`](https://carbium.sh/docs#websocket) mentions of the wallet, since the owner signs any transfer out, and then repeat `getTokenAccountsByOwner`. Each subscription costs credits to open.

## Related

- [Wallet token holdings](https://carbium.sh/library/usecase/wallet-token-holdings) (Use cases, UC0005)
- [Edge worker RPC reads](https://carbium.sh/library/integrate/edge-worker-rpc-reads) (Integrations, I0007)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
