Documentation menu

Network fees (forwarder mode)

In forwarder mode the gateway's fee wallet pays TRX to sweep each deposit address to the project wallet. That is an estimated 11 to 13 TRX per sweep at today's energy price, plus roughly one more USDT transfer's worth of energy for the first sweep that pays a fee (see the cost section of the design document; these numbers are estimates until measured on Nile). On a hosted instance that cost lands on the operator. The network fee lets the operator recover it in USDT, per invoice, from the payment itself.

Unique-amount mode never charges this fee. There is nothing to sweep.

Fees are off until the operator sets a fee collector address. With no collector, every invoice has network_fee: null and every sweep sends everything to the project wallet, exactly as before.

How it works in one paragraph

When a forwarder invoice is created, the gateway takes the project's fee, who pays it, and the operator's collector address, and hashes them into the deposit address together with the project wallet. The deposit address is a small contract. When it is swept, it sends the fee to the collector, once, and everything else to the project wallet. Nobody can change those terms afterwards, not even the operator: naming another collector or a higher fee simply points at a different, empty address. The full argument is in section 11 of the design document.

Settings

Per gateway (environment)

Variable Default Meaning
FEE_COLLECTOR_ADDRESS The operator's wallet that receives the fees, on every network. Unset means no fees are charged
FEE_COLLECTOR_ADDRESS_MAINNET, FEE_COLLECTOR_ADDRESS_NILE, FEE_COLLECTOR_ADDRESS_SHASTA Per-network collector. Overrides FEE_COLLECTOR_ADDRESS for that network
SWEEP_FEE_DEFAULT 0 Fee per invoice, in USDT, for projects that have not set their own. 0 charges nothing
TRX_USDT_RATE What one TRX costs in USDT, for example 0.28. Only used to recommend a fee and to compare fees collected with TRX spent. An admin can override it in the dashboard

The collector must be a wallet whose key is not on the server: a hardware or cold wallet is fine. The server refuses to start when a collector is the fee wallet (on any network), the token contract, the forwarder factory, or MERCHANT_ADDRESS. A project whose wallet is the collector is refused with 409 wallet_is_fee_collector. Do not use an exchange deposit address: fees arrive from a contract, and some exchanges do not credit those.

Per project (admins only)

Setting Values Meaning
sweep_fee USDT amount as a string, for example "1.5". null The fee per invoice. null follows SWEEP_FEE_DEFAULT. "0" turns the fee off for this project. At most as many decimals as the token (6 for USDT)
sweep_fee_payer merchant (default) or customer merchant: the customer pays the round amount and the fee comes out of what the wallet receives. customer: the fee is added to amount_due and shown on the checkout

In the dashboard: Project → Settings → How customers pay → Network fee. Enter the fee (leave it empty to follow the default), choose who pays, and press Save fee. Members see the fee and who pays it on the same card, read-only.

Through the dashboard API (an admin's session cookie and the header X-Qirsh-CSRF: 1):

PATCH /dashboard/api/projects/prj_4mJ0c8vQx1Zr2bTn/settings
Content-Type: application/json

{ "sweep_fee": "1.5", "sweep_fee_payer": "customer" }

PATCH /dashboard/api/admin/projects/:pid takes the same fields. The answer is the project:

{
  "id": "prj_4mJ0c8vQx1Zr2bTn",
  "object": "project",
  "deposit_mode": "forwarder",
  "sweep_fee": "1.5",
  "sweep_fee_is_default": false,
  "sweep_fee_payer": "customer",
  "fee_collector": "TCo11ector..."
}

sweep_fee is the fee in force (the project's own, or the default when sweep_fee_is_default is true). It is charged only while fee_collector is set. Send "sweep_fee": null to follow SWEEP_FEE_DEFAULT again. A member who sends these fields gets 400 invalid_request.

Every change is written to the activity log as project.sweep_fee_changed or project.sweep_fee_payer_changed, with the old and new values (Admin → Activity). The stored fee is in base units, so the log shows 1500000 for 1.5 USDT.

The single-store project

The project from .env takes its fee from SWEEP_FEE_DEFAULT. An admin can still give it its own sweep_fee and sweep_fee_payer in the dashboard: these two settings are not managed by the environment.

Fees apply to new invoices only

Each invoice keeps a snapshot of the fee, the payer and the collector it was created with, and its deposit address is derived from them. So changing sweep_fee, sweep_fee_payer, SWEEP_FEE_DEFAULT or the collector affects new invoices only. Open invoices, and any later payment to an old address, keep the old terms.

For any deposit address:

Invoice fields

Every invoice (API, webhooks, the Node SDK) carries these fields. In unique-amount mode and when no fee applies, network_fee is null, amount_net equals amount_paid (or amount_due before payment), and fee_units is "0".

{
  "amount": "49.9",
  "amount_due": "51.4",
  "amount_paid": "51.4",
  "network_fee": { "amount": "1.5", "payer": "customer", "collector": "TCo11ector..." },
  "amount_net": "49.9",
  "sweep": {
    "status": "swept",
    "tx_id": "a41c...",
    "tx_url": "https://tronscan.org/#/transaction/a41c...",
    "amount_swept": "49.9",
    "fee_paid": "1.5",
    "swept_at": "2026-12-04T07:06:30.000Z",
    "attempts": 0,
    "error": null
  },
  "forwarder": {
    "factory": "TQx8...",
    "destination": "TJ4kA5wRUM9f3xLtBTrPdT5ri7Q2kbUhAF",
    "salt": "0x5f1e...",
    "version": 2,
    "collector": "TCo11ector...",
    "fee_token": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
    "fee_units": "1500000"
  }
}
Field Meaning
network_fee { amount, payer, collector } for the fee bound into this invoice's address, or null
amount_net What the project wallet receives for this invoice: amount_paid (or amount_due before payment) minus the fee, never below 0
sweep.amount_swept What has reached the project wallet so far
sweep.fee_paid What has reached the collector so far: "0" or the full fee
forwarder.version Contract generation: 2 for current invoices, 1 for invoices created before sweep fees existed
forwarder.collector, forwarder.fee_token, forwarder.fee_units The fee terms in the form the factory takes them, for a manual flush. null, null and "0" for an address without a fee

The invoice CSV export adds the columns network_fee, network_fee_payer and amount_net. GET /api/v1/invoices/:id/sweeps adds fee_taken per sweep transaction: the part of amount_moved (base units) that went to the collector.

Worked examples

An order of 49.90 USDT with a sweep_fee of 1.5 USDT.

sweep_fee_payer: merchant sweep_fee_payer: customer
amount 49.9 49.9
amount_due (customer sends) 49.9 51.4
Checkout shows 49.9 USDT 51.4 USDT and a line "Network fee 1.5 USDT (included)"
network_fee.amount 1.5 1.5
Collector receives (sweep.fee_paid) 1.5 1.5
amount_net, project wallet receives (sweep.amount_swept) 48.4 49.9

The fee is charged once per invoice, not per payment. A customer who pays 20 and then 29.9 to a merchant-pays invoice still pays one fee of 1.5. An overpayment of 60 on the same invoice gives amount_paid: "60" and amount_net: "58.5".

With merchant, the customer sees nothing about the fee and the public checkout JSON (/pay/:id/status) carries no collector address. With customer, the checkout JSON carries network_fee: { "amount": "1.5" } and the page shows the fee line in English and Arabic.

Rules and limits

Smallest invoice

Every forwarder invoice must be at least SWEEP_MIN_AMOUNT (default 1 USDT). With merchant, what is left after the fee must also be worth sweeping: amount - fee must be at least SWEEP_MIN_AMOUNT. Below that, creation answers:

{ "error": { "code": "amount_too_small", "message": "Amount must be at least 2.5 USDT for this project (it includes a 1.5 USDT network fee)." } }

with status 400. With customer the fee is added on top, so only SWEEP_MIN_AMOUNT applies.

Dust: a balance no larger than the fee

A sweep takes the fee only when the balance at the address is strictly larger than the fee still owed. Otherwise it takes no fee and sends the whole balance to the project wallet, and the fee stays owed by that address. The next larger balance pays it.

So a customer's 1 USDT mistake is never turned into operator income, and nothing is ever stuck: any balance can always be swept to the project wallet.

The gateway does not pay for sweeps that would collect no fee. Such a balance is held at the address (sweep.status: "skipped", error "held at the deposit address (the balance does not exceed the network fee)"). Sweep now refuses it with 409 below_minimum. An admin can force it (dashboard, or npm run admin -- sweep <invoice> --force), knowing that the fee wallet then pays TRX for a sweep that earns nothing. If more arrives later and the balance exceeds the fee, the next sweep takes it.

Anyone may flush an address themselves and pay the TRX. For a balance larger than the fee, they pay the fee to the collector like anyone else. For dust, the merchant gets it all and the address still owes the fee. The gateway notices a flush by someone else, marks the invoice swept and reads what fee the address paid.

A collector that cannot receive

If the collector cannot receive the token (for example it was frozen by the issuer), the fee transfer moves nothing. The contract then skips the fee and pays the project wallet in full. A collector can never hold a merchant's funds hostage. The fee stays owed by that address.

Fees and the other sweep limits

The fee changes nothing about SWEEP_MIN_AMOUNT, SWEEP_STRAY_MIN_AMOUNT, SWEEP_FEE_LIMIT_TRX and SWEEP_PROJECT_DAILY_BUDGET_TRX (Configuration). They still apply. A dry run that reports a larger fee than the bound one is treated as a failed attempt and nothing is sent.

Choosing a fee: the Fee wallet tab

Admin → Fee wallet shows, per network:

Qirsh asks no price service. Enter the TRX price on that tab (for example 0.28 USDT per TRX), or set TRX_USDT_RATE. The value from the tab wins; clearing it falls back to TRX_USDT_RATE. The recommendation is the bare average cost: add your own margin for energy price changes.

The same data is available to admins as JSON:

PUT /dashboard/api/admin/settings
Content-Type: application/json

{ "trx_usdt_rate": "0.28" }
{ "trx_usdt_rate": "0.28", "trx_usdt_rate_source": "admin" }

Send null to clear it. trx_usdt_rate_source is admin, env (from TRX_USDT_RATE) or null. A rate that is not a positive decimal answers 400 invalid_request.

GET /dashboard/api/admin/forwarder returns the report. One network, shortened:

{
  "trx_usdt_rate": "0.28",
  "trx_usdt_rate_source": "admin",
  "networks": {
    "nile": {
      "fee_collector": "TCo11ector...",
      "sweep_fee_default": "0",
      "avg_fee_trx": "12.4",
      "avg_fee_sample": 20,
      "recommended_sweep_fee": "3.472",
      "projects": [
        {
          "id": "prj_4mJ0c8vQx1Zr2bTn",
          "name": "Hoodie Shop",
          "deposit_mode": "forwarder",
          "sweep_fee": "1.5",
          "sweep_fee_payer": "merchant",
          "sweeps": 20,
          "fees_collected": "30",
          "trx_spent": "248",
          "trx_spent_value": "69.44",
          "covered": false
        }
      ]
    }
  }
}

Measure the real cost on Nile before you choose a mainnet fee.

Invoices from before sweep fees (v1)

Sweep fees need version 2 of the forwarder contracts. A v1 factory and its addresses use a different salt scheme, and this version of Qirsh signs no v1 call.

Recovering an address with a fee

A v2 deposit address depends on its fee terms as well as the factory, the wallet and the invoice id. To recompute it without the database, give recover-forwarder the same terms:

npm run admin -- recover-forwarder --network mainnet --factory T... --destination <project wallet> \
  --invoice inv_... --collector T... --fee 1.5          # add --send to flush

--collector and --fee default to FEE_COLLECTOR_ADDRESS and SWEEP_FEE_DEFAULT. Pass --fee 0 for an address created without a fee. If a project had its own fee, pass that. A wrong guess is harmless: it derives a different, empty address and nothing is sent. The terms of each invoice are in its forwarder object (collector, fee_units) and in the CSV of npm run admin -- forwarders, so stores that save forwarder with the order have everything.

What the store checks

The rule from the integration guide does not change: fulfil on invoice.paid only, idempotently, after checking that the payment covers the order. invoice.swept is for accounting and never triggers fulfilment.

Who charges this fee

The software author charges nothing. The fee is set by whoever operates the gateway, and goes to the operator's wallet. An operator who charges it must say so in the terms merchants accept (the Terms of Service template has a section for it), and with customer the checkout shows it to shoppers before they pay. Merchants see the fee and the net amount on every invoice, webhook and CSV row.

Edit this page on GitHub