Testnet only. Sei Atlantic-2, chain 1328.Not audited. Test funds only.

Build

SDK quickstart

Make a wallet, deposit, pay by link and claim from TypeScript.

On this page
  1. Set up
  2. Deposit
  3. Pay by link and claim
  4. Withdraw
  5. Scan from scratch

batin-sdk is how another project joins the one Batin pool. It is not a second pool, and it is not a hosted wallet. The seed stays in the caller's process. The package is Apache-2.0 and ships compiled JavaScript with type declarations.

npm install batin-sdk

Testnet only (Sei Atlantic-2). The SDK, circuit and pool are not audited.

The live pool is DEPLOYMENT (Atlantic-2, chain 1328, 0x5cCd205EED235d74f31A3c350Ece94AF11E07E72). BatinWallet refuses any other pool unless a local test passes allowOtherPool. A second pool would be a separate anonymity set. Assets are 1n (SEI) and 2n (USDC).

The SDK does not bundle a prover. snarkjs is GPL-3.0; you pass in a function with the same shape as snarkjs.groth16.fullProve. See Licences. The circuit does not prove note ciphertexts. buildTx runs that check, so build payments through BatinWallet rather than a witness of your own.

Set up

import * as snarkjs from "snarkjs";
import {
  BatinWallet, deriveKeys, generateSeed, publicClient, batinSubmitter,
  callArgs, encodeAddress, BATIN_POOL_ABI, DEPLOYMENT, RELAYER_URL,
} from "batin-sdk";

// Download once: https://batin.vercel.app/circuit/joinsplit-841ccf89f1fb.wasm
//                https://batin.vercel.app/circuit/joinsplit-6138886f088c.zkey
const WASM = "joinsplit.wasm", ZKEY = "joinsplit.zkey";
const prover = (input: Record<string, unknown>) => snarkjs.groth16.fullProve(input, WASM, ZKEY);

const seed = generateSeed();                       // 32 random bytes: keep it secret
const wallet = new BatinWallet(deriveKeys(seed), { client: publicClient(), prover });
console.log(encodeAddress(wallet.address));        // batin1…
console.log(RELAYER_URL);                          // the relayer of this pool

Deposit

A deposit is proved locally and sent by the depositor, who owns the refund. The relayer does not send deposits. The deposit itself is public.

const tx = await wallet.shield(1n, 10n ** 17n);    // 0.1 SEI, tokenId 1
const hash = await walletClient.writeContract({
  address: DEPLOYMENT.pool, abi: BATIN_POOL_ABI, functionName: "shield",
  args: callArgs(tx), value: tx.extAmount,         // value only for SEI; approve USDC first
});

The deposit is now pending. On testnet, ask the approval service to admit it:

await fetch("https://batin.vercel.app/api/asp/v1/approve", {
  method: "POST", headers: { "content-type": "application/json" },
  body: JSON.stringify({ id: depositId.toString(), commitments: [c0, c1] }), // from DepositPending
});
const info = await (await fetch(`${RELAYER_URL}/v1/info`)).json();
const submit = batinSubmitter();

await wallet.sync();
const { url, tx: pay } = await wallet.createPaymentLink(1n, 5n * 10n ** 16n, info.relayer, "https://batin.vercel.app");
await submit(pay);                                  // share `url` through the share sheet

const bob = new BatinWallet(deriveKeys(generateSeed()), { client: publicClient(), prover });
const result = await bob.claim(url, submit, info.relayer);
// { status: "claimed" | "already-claimed" | "not-found" | "wrong-network" }

Withdraw

await bob.sync();
const out = await bob.unshield(1n, 4n * 10n ** 16n, "0xRecipient…", 10n ** 16n, info.relayer);
await submit(out);

Scan from scratch

const restored = new BatinWallet(deriveKeys(seed), { client: publicClient(), prover });
const state = await restored.sync();               // full view-key scan of pool events
state.balances;                                    // { "1": bigint, "2": bigint }

The public RPC caps eth_getLogs at 2,000 blocks, so a full scan walks the chain from the deploy block in chunks. The app keeps an incremental cache; a hosted indexer is an open item.

Source: apps/web/content/docs/sdk-quickstart.md