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

Build

SDK reference

The public surface of batin-sdk.

On this page
  1. BatinWallet
  2. Keys and backup
  3. Links
  4. Chain and relay
  5. Types

All amounts are bigint base units (SEI: 18 decimals; USDC: 6). Token ids: 1n SEI, 2n USDC.

BatinWallet

new BatinWallet(keys: AccountKeys, opts: { client: PublicClient; prover: Prover; pool?; chainId?; fromBlock?; allowOtherPool? })

pool and chainId default to DEPLOYMENT. Any other value throws unless allowOtherPool is set, which is for a local test only. shield, payAddress, createPaymentLink, unshield, and claim accept token ids 1n and 2n only.

Member Returns Notes
address Address { ownerPub, viewPub }; encode with encodeAddress
sync(minBlock?) ScanResult Full scan; retries until events cover nextIndex
balance(tokenId) bigint From the last sync
shield(tokenId, amount) ProvedTx Submit yourself with shield(...callArgs(tx))
createPaymentLink(tokenId, amount, relayer, origin?) { url, link, tx } url carries the secret in its fragment
paymentRequest(opts?, origin?) { url, request } No proof and no transaction. opts is { tokenId?, amount?, label? }; token or amount 0n means the payer chooses
payAddress(tokenId, amount, to, relayer) ProvedTx Private transfer to a batin1 address. This is how a request is paid
unshield(tokenId, amount, recipient, fee, relayer) ProvedTx fee must meet the relayer minimum
claim(urlOrLink, submit, relayer) ClaimResult Handles races; claimed only after a scan accepts the note

Keys and backup

Function Purpose
generateSeed() 32 random bytes
deriveKeys(seed) { spendKey, viewKey, ownerPub, viewPub }
encodeAddress(addr) / decodeAddress(s) batin1… with checksum
makeBackup(seed, passphrase, prf?) BackupFile; passphrase ≥ 12 chars, scrypt N = 2^17
restoreBackup(file, { passphrase } | { prfOutput }) seed
createPrfPasskey(rp, userName) / getPrfOutput(rp, credentialId) WebAuthn PRF (browser only)
Function Purpose
newLink(chainId, pool, tokenId, amount) Fresh random link
formatLink(link, origin) / parseLink(url) /c#v1.<chain>.<pool>.<payload>
requestFor(address, chainId, pool, opts?) Build a request. Amount without an asset throws
formatRequest(request, origin) / parseRequest(url) /r#v1.<chain>.<pool>.<payload>
linkCommitment(link) The commitment the sender paid into

Chain and relay

Export Purpose
ATLANTIC_2, DEPLOYMENT, RELAYER_URL viem chain, the live pool, and its relayer (https://batin.vercel.app/api/relay)
publicClient(rpc?) viem public client for Atlantic-2
fetchPoolEvents(client, pool, from, to?, minBlock?) Chunked log fetch
scanEvents(events, keys, chainId, pool) Decrypt and verify owned notes
isKnownRoot, isSpent Pool reads
callArgs(tx) [proof, args, ext] for shield / transact
relayerSubmitter(base), batinSubmitter() POSTs to ${base}/v1/transact. batinSubmitter is the shared relayer
provedTxToJSON / provedTxFromJSON Wire format
BATIN_POOL_ABI Pool ABI

Types

type Prover = (input: Record<string, unknown>) => Promise<{ proof: any; publicSignals: string[] }>;
type ClaimResult =
  | { status: "claimed"; hash: Hex; note: OwnedNote }
  | { status: "already-claimed" } | { status: "not-found" } | { status: "wrong-network" };
interface ScanResult { leaves: bigint[]; notes: OwnedNote[]; deposits: PendingDeposit[]; balances: Record<string, bigint> }

Lower-level modules (Poseidon, Merkle tree, join-split witness builder, BabyJubJub, note encryption) are exported too; see packages/sdk/src. Test vectors for every module are in test-vectors/.

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