Skip to main content
The Renaiss TypeScript SDK gives you typed helpers for public gacha discovery and authenticated gacha flows. Use a public client for read-only data. Use an authenticated client when a user needs to sign in or read account data. Add an approved builder API key when that client will prepare wallets, pull gacha, or accept buyback offers.
The SDK is in alpha. APIs may change before the first stable release.

Quickstart

1

Install the package

Install the client package and viem if you want to use the built-in viem signer adapters.
2

Create a public client

Create a read-only client for public gacha discovery.
3

Fetch gacha machines

Fetch a page of active gacha machines.
4

Create an authenticated client

Sign in with SIWE, create a user API key, then pass that key and your approved builder API key to createSecureClient for write workflows.
5

Prepare the wallet and pull gacha

Make the user’s Safe wallet ready, then pull from a machine and update your UI through draw resolution. Token release continues asynchronously.
The client targets Node.js 24 or later. By default, requests go to https://api.renaiss.xyz. Set RENAISS_API_URL or pass baseUrl to point at another environment.
Builder-authorized write workflows also need a pre-provisioned approved builder API key. Set it in your app configuration and pass it as builderApiKey only on secure clients that call wallet, pull, or buyback write methods. To attribute pulls on-chain, also set a builder code and pass it per pull as builderCode. See Builder code attribution.

SDK patterns

The SDK uses the same patterns across public and authenticated workflows: paginated list methods, Result values for expected failures, and action-specific error guard utilities.

Pagination

List methods return a lazy paginator. Use firstPage() when you only need one page.
Use for await to iterate through pages. Each page is still a Result, so handle failures inside the loop.
You can resume from a cursor returned by a previous page.

Error handling

The SDK returns expected failures as Result values. It does not throw for request validation errors, API errors, schema validation errors, or handled signing failures. Use isFailed() and getError() for general handling. Use action-specific error guard utilities when you want exhaustive handling for one action.
Available guard utilities include:
  • isListGachaMachinesError
  • isPullGachaError
  • isListGachaBuybackOffersError
  • isFetchGachaDrawStatusesError
  • isBuybackGachaError
  • isIsSafeWalletDeployedError
  • isDeploySafeWalletError
  • isIsPermit2UsdtApprovedError
  • isApprovePermit2UsdtError
  • isEnsureSafeWalletReadyError

Public client

Public clients can call unauthenticated endpoints such as gacha machine discovery, machine detail, and machine contents.

Authenticated client

Authenticated clients need a user API key. The SDK can create one by asking the user’s wallet to sign a SIWE message, then exchanging the session for an API key. createSecureClient({ apiKey }) is enough for authenticated reads:
  • fetchAuthenticatedUser
  • listGachaBuybackOffers
  • listUserActivities
  • fetchGachaDrawStatuses
Builder-authorized write workflows also need builderApiKey:
  • ensureSafeWalletReady
  • isSafeWalletDeployed
  • deploySafeWallet
  • isPermit2UsdtApproved
  • approvePermit2Usdt
  • pullGacha
  • buybackGacha
Use a pre-provisioned approved builder API key. The SDK sends x-builder-api-key only for write-authorized requests, not for SIWE API key creation or authenticated reads.

Wallet integrations

The signer must implement the Renaiss signer interface. The viem adapter can use a private key, an existing viem wallet client, or an injected browser provider.
Never expose private keys in browser code. For browser wallets, adapt the user’s injected provider instead of using privateKey.

Ensure wallet ready

Gacha write flows use the authenticated user’s deterministic Safe wallet and Permit2 USDT approval. They require both the user API key and the secure client’s builderApiKey. Call ensureSafeWalletReady() before letting a user pull gacha or accept buyback offers. It deploys the Safe if needed and approves Permit2 USDT if needed. isSafeWalletDeployed() and isPermit2UsdtApproved() also need builderApiKey because they call prepare routes for sponsored write operations.

Check wallet deployed

Use isSafeWalletDeployed() when you only need to check whether the authenticated user’s Safe already exists.

Deploy wallet

Use deploySafeWallet() when you want wallet deployment as a separate step.

Approve Permit2 for custom flows

Most integrations should call ensureSafeWalletReady(). Use approvePermit2Usdt() explicitly when your flow handles deployment and token approval in separate screens.
You can also check approval status without submitting an approval transaction.

Discovery

Use discovery methods to browse gacha machines, machine contents, buyback offers, and user activity feeds. List methods return paginated Result values, so use the same pagination and error handling patterns from SDK patterns.

Gacha machine

Use gacha machine methods to fetch one machine, inspect its contents, pull from it, stream pull progress, and submit buybacks for eligible cards.

Fetch a gacha machine

Use fetchGachaMachine() when you already have a machine slug and need the full machine object.

Pull gacha

Use pullGacha() from a secure client after the user’s wallet is ready. The secure client must include builderApiKey. The SDK prepares the pull, asks the signer for the Safe typed-data signature, submits the pull, and streams progress through aggregated draw resolution. Token release continues asynchronously after the stream closes.

Builder code attribution

pullGacha() accepts an optional builderCode for on-chain attribution. Pass a bytes32 value: 0x followed by 64 hex characters.
The code is set per pull, not on the client. Pass a different value on each call when one integration attributes pulls to more than one campaign. The API resolves the code into the Permit2 witness that the user signs, and the SDK submits the same resolved value with the pull. When you omit builderCode, the API signs and submits the zero bytes32 value.
builderCode is public on-chain data, not a secret. It is separate from builderApiKey, which authorizes the write and must stay server-side. A pull still needs builderApiKey on the secure client.
If builderCode is not a valid bytes32 value, the SDK returns a WRONG_REQUEST_PARAMS result before preparing the pull.

Pull gacha SSE stages

pullGacha() accepts onEvent, which receives validated SSE events in arrival order. Use these events to show progress until every selected draw resolves. The final pullGacha() result still returns a Result. If the stream emits an error event or closes before every selected draw appears in a completed GACHA_V3_DRAW_RESOLVED event, the SDK returns a failed result. A successful result contains draws, events, and txHashes. It does not wait for token release. Each action can arrive with these statuses:

Track asynchronous settlement

Use fetchGachaDrawStatuses() to recover resolved draws after an interrupted or timed-out stream. You can also use it to check whether each token was assigned, released, or bought back. This authenticated read needs the user’s API key. It does not need builderApiKey.
machineId is the gacha machine’s internal UUID, not its slug. pullTransactionHash is the transaction hash from the completed GACHA_V3_OPEN_PACK event.
The SDK’s public gacha machine models currently expose the machine slug, but not its internal UUID. Call fetchGachaDrawStatuses() only if your integration already has that UUID.

Buyback

Use listGachaBuybackOffers() to show available offers, then pass one or more compatible offers to buybackGacha(). Listing offers is an authenticated read; submitting the buyback requires builderApiKey. Offers in one request must share a pack, vending machine, and token. The SDK combines up to 10 unique settlement IDs and aggregates their authorized amount before signing.