At a glance
Prerequisites
- Zama yields enabled for your project. Enable them in the Yield.xyz dashboard, from your project’s enabled-yields list. If you do not have a project yet, set one up first. Start with the Sepolia vault.
- ETH for gas on Ethereum. A deposit has a high gas limit: at least 1,500,000 gas for each vault leg. The node checks that the wallet can pay the gas limit at the maximum fee before it accepts the transaction, so keep more ETH in the wallet than the deposit usually costs.
- A signer that signs EIP-712 typed data and sends transactions. Revealing a balance needs an EIP-712 permit signed by the owner. Every action returns unsigned transactions that the same wallet signs.
- The Zama SDK. Install
@zama-fhe/sdk@3.7.0. The Zama SDK docs cover it in full. The examples use viem.
We construct. You sign. Every action returns unsigned transactions. Yield.xyz never holds keys and never signs on your behalf. Inspect
unsignedTransaction before you sign it, and never change its to, data or value. The nonce is the wallet’s pending nonce when the action was built, and every step of a multi-step action carries that same value, so let your signer assign the nonce for each step after the first. See step 6.Basics
The examples use these variables:
The lifecycle
Ten steps cover every flow, in this order: discover, get the confidential token, set up the SDK, encrypt, enter, sign and submit, read and reveal balances, exit privately, exit instantly, and cancel.1. Discover the vaults
status.enter and status.exit turn false while the vault’s own batcher is paused. Check them before you offer the vault.
The helper below collects these addresses. Later steps use it:
2. Get the confidential token
A deposit takes the confidential token only. To deposit a plain token, wrap it first. Wrapping happens outside the Yield.xyz API, on the confidential token contract, in up to three transactions:- If the wallet’s allowance for the confidential token is non-zero but too low, reset it to zero. USDT, for example, reverts when one non-zero allowance changes to another.
- Approve the confidential token to spend the plain amount.
- Call
wrap(to, amount)on the confidential token.
amount / rate(). rate() converts the plain token’s decimals to the confidential token’s 6 decimals, so read it to know how much to encrypt in step 4. For USDC, USDT and AUSD the decimals match. For WBTC (8 decimals), the wrapper rounds the amount down to a multiple of rate() and refunds the rest. See Zama’s confidential wrapper docs for the contract.
3. Set up the SDK
Create one SDK instance per wallet and chain, pointed at the Yield.xyz relayer proxy. The proxy accepts your Yield.xyz API key and handles the Zama side, so you need no Zama key. It accepts chain ids1 and 11155111, and only the Zama vault contracts that Yield.xyz lists. Zama’s authentication guide explains how the SDK uses relayerUrl and auth.
The SDK asks your signer for EIP-712 signatures when it decrypts. It never sends transactions, because those come from the Yield.xyz API.
sdk.terminate() when you are done with one.
web() runs encryption in a Web Worker that it loads from the package, and falls back to the main thread with a console warning if your bundler cannot load that worker. If encryption freezes the page, copy dist/esm/encrypt.worker.js from @zama-fhe/sdk into your static directory and pass its path: web({ offloadWorker: '/encrypt.worker.js' }). A Content Security Policy then needs worker-src 'self'.
To check the wallet’s confidential token balance before a deposit, decrypt it with sdk.createToken(address).balanceOf(owner). The SDK asks the owner to sign a permit the first time.
4. Encrypt the amount and the legs
A deposit needs two encrypted bundles, made for the depositing wallet:sdk.encrypt, user decryption with a permit (step 7) and public decryption (step 9) in more depth.
5. Enter
SendinputToken set to the confidential token (the encryptedAmount option, for example cUSDC), with the four encrypted arguments, to POST /v1/actions/enter. The API also accepts a request without inputToken, but sending it keeps the request explicit. A plain token such as USDC is rejected with NotImplementedError: wrap it first, as in step 2. The yield’s inputTokens also lists the plain token because the Zama widget wraps it for the user. enter itself accepts only the confidential token.
Response (excerpt)
DEPOSIT transaction comes back. It transfers the encrypted amount to the router, which sends each leg to its vault’s batch. isEncrypted is true, and amount, amountRaw and amountUsd are null because the request left amount out. The action’s encryptedAmount is this vault’s leg handle: the entry of encryptedLegAmounts at this vault’s position in the leg list, encrypted for the router. It is not the encryptedAmount you sent, which the transfer to the router consumes.
Leave amount, amountRaw, shareAmount, shareAmountRaw and useMaxAmount out of a Zama request. The API rejects a non-zero amount or amountRaw, any shareAmount or shareAmountRaw, and useMaxAmount: true. Only an amount of exactly "0" is accepted, and the action then returns "0" in place of null.
Encrypted action fields
Zama actions, in the response toenter, exit and manage and from GET /v1/actions/{id}, carry these extra fields:
The leg order is the
encryptedLegAmounts options order on the yield, the same for every wallet. This vault’s leg is the option that also appears in executionContracts.
6. Sign, broadcast and submit the hash
Run each transaction through the same loop as any other yield, instepIndex order: sign unsignedTransaction, broadcast it, report the hash with PUT /v1/transactions/{transactionId}/submit-hash, then poll GET /v1/transactions/{transactionId} until the status is terminal. Start a step only after the previous one confirms. See Enter and exit flows for the full loop and Transaction signing for EVM signing code.
All steps of an action are built when the action is created, so they all carry the same nonce: the wallet’s pending nonce at that moment. For every step after the first, let your signer assign the nonce, or read the wallet’s pending transaction count just before signing. Reusing the returned value for a second step fails with replacement transaction underpriced or nonce too low. The Zama widget leaves the nonce to the wallet. The loop below reads the pending count for every step, which also covers the first.
DEPOSIT confirms, the deposit waits in the current batch. It starts earning once that batch settles. A confirmed transaction means the deposit joined the batch, not that the batch settled. The action records the outcome in events, on GET /v1/actions/{id}: DEPOSIT_SETTLED when the batch settles, or DEPOSIT_CANCELLED if the deposit is canceled. Show the deposit as submitted, awaiting settlement, until one of them appears. Events are recorded within about 10 minutes of the on-chain outcome.
Action (excerpt)
7. Read and reveal balances
The per-yield call reads the vault on-chain, so it returns a settled position wherever it was created, including in the Zama app. The network-wide
POST /v1/yields/balances call is different: a query without yieldId covers only the yields that address has already used through Yield.xyz.If your project returns balances only for yields the address has used through Yield.xyz, both calls return an empty list for a vault the address has not used through Yield.xyz, even with a yieldId.yieldId. Queries with a yieldId are always returned, unless your project returns balances only for yields the address has used, as described in the note above. Pending requests made outside Yield.xyz are not returned by either call; see below.
isEncrypted: true, an empty amount, amountUsd set to null, and the encrypted handle in shareAmountRaw. The one plain row is the withdrawable row of an instant exit whose WITHDRAW has confirmed (see step 9). shareToken is the token the position is held in: the confidential token (for example cUSDC) for entering, and the confidential share token (for example csteakcUSDC) for active and exiting. A revealed amount is in shareToken units, so label it with shareToken. When you convert an active or exiting share amount into an asset value, label it with the balance row’s token. On active, entering and exiting rows that is the confidential token (for example cUSDC), not the plain token that the yield’s own token names. The row’s token is the plain token (for example USDC) only on the withdrawable row of an instant exit.
On
entering and exiting rows, date is when the batch can next settle. It applies while the batch can still be canceled. Once the batch has been sent to the vault, an entering row drops its date, and an exiting row can keep its old date for a short time, as described below. Pending rows appear only for batches the wallet joined through Yield.xyz actions. A deposit or private withdrawal submitted only outside Yield.xyz, for example in the Zama app, does not appear as entering or exiting. Once the batch settles, a deposit shows in active. A private withdrawal does not create a balance row: the batch pays the confidential token (for example cUSDC) to the wallet, so check the wallet’s confidential token balance. An instant exit started outside Yield.xyz has no withdrawable row, because only unwraps requested through Yield.xyz actions are tracked.
Pending rows follow the chain with a short delay. After a batch settles, active reflects it straight away. The entering or exiting row can stay until the settlement is recorded: usually under 10 minutes for a deposit, and up to about 20 minutes for a private exit. During that window an exiting row can still show its old date and a CANCEL_PENDING action. Don’t send it: the batch has already settled and the cancel reverts. Use the action’s events (DEPOSIT_SETTLED, REDEMPTION_SETTLED) as the settlement signal, and treat a pending row as stale once its action has one. An encrypted row is unknown until it is revealed. Only a revealed zero means nothing is pending. A row that reveals as zero in a vault you did not choose is the encrypted-zero leg of a deposit or withdrawal and needs no action.
To reveal, decrypt the handles with the owner’s permit. Each handle is decrypted against its own contract: the share token for active, this vault’s deposit leg for entering, and this vault’s redeem leg for exiting.
active balance as an asset value, use state.pricePerShareState.price on the yield. It is the asset value of one whole share, so convert the revealed base units to whole shares first: (shares / 10^shareToken.decimals) * price. Use decimal-safe arithmetic, because multiplying the base units directly overstates the value by 10^decimals. Label the result with the row’s token (for example cUSDC).
Revealed amounts belong to the owner. Keep them in memory, and clear them when the wallet changes.
A deposit or a private withdrawal sends an encrypted zero to every other vault of the same asset. Those vaults can show an encrypted balance for the wallet that reveals as zero. Your app can drop a position once it reveals as zero, as the Zama widget does.
8. Exit privately
A private exit redeems shares in the next redemption batch and pays out the confidential token. LeaveoutputToken out, or set it to the confidential token, and send legs for the redeem batchers. The legs carry the share amount, encrypted for the router, with 0 for every other leg. A private exit sends no encryptedAmount.
The first private exit can return several
SET_OPERATOR transactions, one for each vault of the same asset. Sign them before the REDEEM, one at a time, and let your signer assign the nonce for each one after the first (see step 6). The REDEEM is built before any SET_OPERATOR confirms, so after the last SET_OPERATOR confirms, estimate its gas again (for example with publicClient.estimateGas) and set gasLimit to the result before you sign it. When the batch settles, the wallet receives the confidential token. There is nothing to claim. The exit action records REDEMPTION_SETTLED in events when the batch settles, or REDEMPTION_CANCELLED if the withdrawal is canceled.
9. Exit instantly
An instant exit skips the batch and pays out the plain token. Its amount becomes public on-chain. SetoutputToken to the plain token (token.address) and send encryptedAmount and encryptedAmountProof, encrypted for the confidential share token (the exit encryptedAmount option):
UNWRAP transaction comes back. It burns the shares and marks the burned amount for public decryption. Once it confirms, and usually within about 10 minutes, the balances show a withdrawable row with a WITHDRAW pending action:
Balance (excerpt)
POST /v1/actions/manage with the pending action’s passthrough unchanged. A public decrypt needs no signature.
WITHDRAW finishes the unwrap, then REDEEM redeems the vault shares for the plain token. Both are built in this call and carry the same nonce. Sign and confirm WITHDRAW first, then sign REDEEM with a nonce your signer assigns (see step 6).
Resume an interrupted instant exit
An instant exit can stop at two points:
The Zama widget resumes this stage from the action, too.
An instant exit started outside Yield.xyz, for example in the Zama app, has no
withdrawable row, so it cannot be finished through the API. Finish it in the app where it started.
10. Cancel a pending request
entering and exiting rows carry a CANCEL_PENDING pending action while their batch can still be canceled. A settled exiting row can show a stale one for a short time, as described in step 7. Send it to POST /v1/actions/manage with the passthrough copied from the balance:
cURL
CANCEL_PENDING transaction comes back. It refunds everything the wallet has in that batch, including amounts added to the same batch outside Yield.xyz, such as in the Zama app. A request made only outside Yield.xyz has no pending row, so it cannot be canceled through the API. A canceled deposit returns the confidential token. A canceled exit returns the share token.
While a cancel is broadcast but not yet confirmed, the row stays and its CANCEL_PENDING action is not offered. The row disappears once the cancel confirms, and the original deposit or exit action records DEPOSIT_CANCELLED or REDEMPTION_CANCELLED in events.
Reward rate
The yield’s reward rate is the vault’s base APY. The Sepolia test vault reports no reward rate. Zama runs separate incentive campaigns that holders opt into in the Zama app. The API does not perform that opt-in, and the reward rate does not include those incentives.Errors and troubleshooting
Errors use the shared error envelope, in three shapes. A typed error puts the error name inmessage (for example InvalidArgumentError or MissingArgumentsError), the explanation in details.reason and, for MissingArgumentsError, the missing names in details.arguments. An enter that leaves out a required argument returns Field '<name>' is required in message, as in the second example. A request whose body fails format validation returns Bad Request Exception with validation.message, a list of constraint messages. Branch on statusCode and the error name. details.reason is display text, and its wording can change.
Next steps
Zama widget
Embed confidential vaults with the Yield.xyz widget.
Zama vaults
How confidential deposits, batches and exits work.
Enter and exit flows
The full sign, submit and poll loop.
Transaction signing
EVM signing code for the transactions the API returns.
Zama documentation
Zama’s SDK docs: configuration, encryption, decryption and confidential tokens.

