> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privacyboost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Fees

> What users pay for each operation, who pays the gas, and how to show a fee before a send.

# Fees

Transfers, unshields, earn, and swaps carry a private fee paid in the token
being moved. The fee is charged on top of the amount: the notes the sender
spends cover `amount + fee`, and exactly `amount` reaches the recipient or the
gateway call. Users pay no gas for these operations. The operator's relay
submits each epoch on-chain and pays its gas.

The operator sets these fees for each app and chain, and can override them for
individual wallets. Read them for the signed-in user at runtime instead of
hard-coding them. The on-chain rules behind them are in the protocol's
[fee model](https://docs.privacyboost.io/technical-explainer/protocol.md#fee-model).

## Fees by operation

| Operation | Fee | Gas paid by |
| - | - | - |
| Shield | None | The user's wallet, for the shield transaction (and the WETH wrap when shielding ETH). The relay pays for the proof that credits it. |
| Transfer | Transfer fee, on top of the amount | Relay |
| Unshield | Unshield fee, on top of the amount | Relay |
| Earn deposit, earn redeem, or swap | Gateway fee in place of the unshield fee, on top of the amount | Relay |
| Portal deposit | Sweep fee, taken out of the swept amount | The sweeper for the sweep, the relay for the credit |
| Claimable transfer: fund | Transfer fee on the gift amount | Relay |
| Claimable transfer: claim or refund | None | Relay |
| Claimable transfer: public exit | On-chain `withdrawFeeBps`, taken out of the amount | The caller |
| Forced withdrawal | On-chain `withdrawFeeBps`, taken out of the amount | Whoever submits the request, and whoever executes it |

Shields and transfers also have minimums. `getRegisteredTokens()` reports a
per-token `minShieldAmount`, and the fee rates carry `minTransferAmountUSD`.

## Transfer and unshield fees

Transfers and unshields each have their own fee mode: flat, or a rate in basis
points (bps), where 1 bps is 0.01%.

A flat fee is set in USD. The server converts it to the token at the current
price, so the token amount moves with the price. A flat transfer fee applies
to every transfer, including a transfer to yourself.

A bps fee is `floor(base * bps / 10000)`. For an unshield, the base is the
withdrawn amount. For a transfer, the base is the value sent to other
accounts. Change and self-transfers add nothing to it.

Because the fee comes on top, unshielding a whole shielded balance fails with
`INSUFFICIENT_BALANCE`. Withdraw at most the balance minus the fee, as the
[withdrawals guide](https://docs.privacyboost.io/sdk/typescript/guides/withdrawals.md#fees) shows.

A transfer must send at least `minTransferAmountUSD` worth of value to other
accounts. Self-transfers are exempt.

The server totals each epoch's fees by token and pays them into one private
note per token, owned by the operator's fee account.

### App-paid fees

An app can run on the `app_pays` fee model. Its users then pay no transfer,
unshield, or gateway fee, and there is no minimum transfer amount. The operator
meters the app's usage instead. The `feeModel` field on the fee rates says
which model applies.

## Gateway fees for earn and swaps

[Earn](https://docs.privacyboost.io/sdk/concepts/earn.md) deposits and redemptions and
[swaps](https://docs.privacyboost.io/sdk/concepts/swaps.md) are gateway unshields. They pay a gateway fee in
place of the unshield fee. It is charged on top of the net amount that enters
the vault or router call, so the input notes cover `amount + fee`. A call that
fails and refunds the input as a private note still pays the fee.

The operator configures the gateway fee per app, chain, and gateway, and can
override it for one call selector or one wallet. It is either flat (set in
USD) or a rate. A gateway rate can be finer than one basis point, so the
rates carry `gatewayFeeRate` over `gatewayFeeRateDenominator` (10000, or
100000 for tenths of a basis point). When no gateway fee is configured for the
app, fee reads and submissions fail with `GATEWAY_FEE_NOT_CONFIGURED`.

`EarnResult.fee` and `SwapResult.fee` report the fee charged.

## Portal deposits

A portal deposit pays a sweep fee. The pool owner sets one rate for every
token, `portalSweepFeeBps`, capped at 10%. Each sweep records the rate at that
moment, and the portal's owner is credited
`gross - floor(gross * feeBps / 10000)`. The fee is paid to the address that
ran the sweep.

A sweep must move at least the token's `portalMinSweep`; a smaller balance
waits at the portal address. When ETH is sent, 0.001 ETH stays at the portal
address as a reserve and is not swept. See
[Portal Deposits](https://docs.privacyboost.io/sdk/concepts/portal-deposits.md) for the full flow.

## On-chain withdrawal fee

The pool contract's `withdrawFeeBps` applies only to the two exits that skip
the operator: forced withdrawals and public gift exits. The pool owner sets it
with `setFees`, capped at 1,000 bps (10%), and it is paid to the `treasury`
address. Epoch transfers and unshields don't use it.

A forced withdrawal records the rate when it is requested and deducts the fee
from the payout when it is executed. A public gift exit applies the current
rate, and its proof binds a minimum net payout. An exit that would pay less
than that minimum reverts.

## Claimable transfers

Claims and refunds of a [claimable transfer](https://docs.privacyboost.io/sdk/concepts/claimable-transfers.md)
pay no fee, so the recipient receives the full gift amount.

## Showing fees before a send

`sdk.vault.getFees(tokenAddress)` returns the rates for the signed-in user and
one token, and needs a signed-in session. Price an amount with `calculateFee`
and display the rate with `formatFeeRate`:

```typescript theme={null}
import { calculateFee, formatFeeRate } from '@sunnyside-io/privacy-boost';

const rates = await sdk.vault.getFees(tokenAddress);

// The recipient receives `amount`; the sender's notes cover amount + fee.
const unshieldFee = calculateFee(rates, amount, 'unshield');
const transferFee = calculateFee(rates, amount, 'transfer');

console.log(`Unshield: ${amount + unshieldFee} (${formatFeeRate(rates, 'unshield')})`);
console.log(`Transfer: ${amount + transferFee} (${formatFeeRate(rates, 'transfer')})`);
```

For a transfer that sends only part of the amount to other accounts, pass
`{ externalVolume }` as the fourth argument. For earn or a swap, read
`sdk.vault.getGatewayFees(tokenAddress, gatewayAddress, gatewaySelector?)` and
price it with `calculateGatewayFee`. The
[fee math reference](https://docs.privacyboost.io/sdk/typescript/api-reference.md#fee-math) lists every
helper.

The SDK reads the rates again and recomputes the fee when it builds the
transaction, so fetch rates close to the confirmation step. A flat fee follows
the token price between the two reads.

In React, [`useFees({ tokenAddress })`](https://docs.privacyboost.io/sdk/react/api-reference#usefees)
fetches the rates and returns `calculateFee(amount, type)` and
`formatFeeRate(type)`. Its `calculateFee` returns `null` until the rates load,
so an unknown fee never shows as zero. Pass `gatewayAddress` to price
`'gateway'` instead.

From the CLI:

```bash theme={null}
privacy-boost fees <TOKEN_ID>
privacy-boost fees <TOKEN_ID> --gateway-address <ADDRESS> [--gateway-selector <0xSELECTOR>]
```

iOS, Android, and React Native expose `getFees(tokenAddress)` and
`getGatewayFees(...)` with the same `FeeRates` shape.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.