Withdrawing Tokens

The withdraw() method lets a user transfer shielded tokens from their private Shielder account back to a public address — using a relayer to maintain privacy.

When to Use

Use withdraw() when a user wants to exit the private set and receive tokens on a public Ethereum address — anonymously, via relayer.

async withdraw(
  token: Token,
  amount: bigint,
  quotedFees: QuotedFees,
  withdrawalAddress: Address,
  pocketMoney: bigint
): Promise<`0x${string}`>

What It Does

  • Fetches the latest state and constructs a withdrawal proof.

  • Sends a withdrawal request to the configured relayer backend.

  • The relayer pays gas and broadcasts the transaction to the network.

  • Funds arrive at the withdrawalAddress, minus relayer fees.

Example

Pocket Money (for ERC-20s only)

If the withdrawal token is not the native token, you may want to request a small native token payment from the relayer to cover gas for the recipient.

Tips

  • amountToWithdraw passed to withdraw() function includes the fee, more precisely withdrawalAddress will receive amountToWithdraw - quotedFees.fee_details.total_cost_fee_token

Last updated