Documentation menu

Concepts

This page explains the words the rest of the docs use. Read it once before you run a gateway or integrate a store.

Gateway and operator

The gateway is one Qirsh server: a Node.js process with a SQLite database. It watches the TRON network through TronGrid, serves the hosted checkout at /pay/<invoice id>, the dashboard at /admin, and the API at /api/v1.

The operator is whoever runs that server. On a hosted instance the operator is a business that offers the gateway to merchants. On a self-hosted one the operator and the merchant are usually the same person.

Projects

A project is one store or app. Each project has:

Only one active project may use a given wallet on a given network. Admins can move a project to another wallet or network. Project members cannot.

The project wallet

The wallet belongs to the store, not to the gateway. Qirsh only ever knows its public address. An admin either pastes the address of a wallet the store already controls (TronLink, a hardware wallet, Trust Wallet and so on), or lets the dashboard generate one. A generated wallet is created in the admin's browser: a 12-word recovery phrase and its private key, compatible with TronLink (path m/44'/195'/0'/0/0). The admin writes the phrase down and the server receives only the address. The gateway cannot show the phrase again or recover it. For wallets that will hold large amounts, create them in TronLink or on a hardware wallet and paste the address. See the Operator guide.

The single-store project from .env

If you set MERCHANT_ADDRESS (and usually API_SECRET_KEY, WEBHOOK_URL and WEBHOOK_SECRET), Qirsh creates a project called Default from those variables and keeps it in sync with them on every start. Its wallet, network, simulation flag, webhook URL and deposit mode can only be changed in the environment. Its API key is API_SECRET_KEY. This is the simplest way to run one store, and it can live next to projects created in the dashboard.

Users

People sign in to the dashboard at /admin with an email and a password.

Role Sees Can change
Admin Every project, the admin console, the fee wallet, the activity log Everything, including wallets, networks, deposit modes, network fees, users
Member Only the projects they were added to Name, brand colour, invoice lifetime, webhook URL and secret, API keys of those projects

The first admin comes from ADMIN_EMAIL and ADMIN_PASSWORD, or from npm run admin -- create-admin you@example.com. Passwords are at least 12 characters and stored with scrypt.

Dangerous actions and the activity log

Some actions can redirect money or lock people out: changing a project's wallet, network or deposit mode, disabling a project, rotating a webhook secret, revoking a project's last API key, changing a user's role, disabling a user or resetting their password. They need the user to type their password again; one confirmation covers 5 minutes in that browser session. Each of them, each new project, each change to a project's network fee and each wrong password on a confirmation is written to the activity log: who, when, from which IP, which project, and the old and new values. Admins see the whole log under Admin → Activity; members see their own project's entries. The log never holds secrets.

API keys and the webhook secret

An API key belongs to exactly one project and only ever sees that project's data. The store's backend sends it as Authorization: Bearer <key>. Keys are stored as SHA-256 hashes, so the dashboard shows a key once, when it is created. A project can have several keys, which makes rotation possible without downtime.

The webhook secret signs every webhook the project receives. The store uses it to check that a webhook really came from the gateway. Admins and members can reveal, copy and rotate it in the project's settings.

Invoices

An invoice is a request for one payment. The store creates it through the API with an amount and, usually, its own order_id. Creating the same order_id again returns the same open invoice, so retries are safe. The response contains a checkout_url for the customer.

Statuses

Status Meaning What the store does
pending Waiting for payment Nothing yet
confirming A matching transfer is on-chain but not yet final Show "confirming". Do not ship
paid The transfer is solidified (final) Fulfil the order, once
expired The deadline passed without a valid payment Release stock, cancel the order

The usual paths are pending → confirming → paid and pending → expired. There is one more: a transfer sent before the deadline but detected after it still settles the invoice, so an invoice can go from expired to paid. Stores must accept that.

Unconfirmed and solidified

TRON blocks become irreversible ("solidified") after about a minute. Qirsh shows a transfer as confirming as soon as it sees it, and marks the invoice paid only once the transfer is solidified.

Unique amount

In the default mode every open invoice on a wallet asks for a slightly different amount. Qirsh adds up to 0.009999 USDT to the price, so a 49.90 order may ask for 49.907423. That fingerprint is how an anonymous transfer is matched to the right invoice. amount is the price you asked for, amount_due is what the customer must send.

Unmatched transfers and manual settlement

A transfer to a project wallet that fits no invoice (wrong amount, too late, a second payment for a paid invoice) is recorded as unmatched. The dashboard lists it under Transfers, and someone can assign it to its invoice. That marks the invoice paid with settled_manually: true and records what actually arrived in amount_paid. Underpaid or out-of-window transfers need an extra confirmation (force).

In forwarder mode the equivalent is accept: the invoice is settled with what its deposit address received. Partial, late and duplicate payments need the same extra confirmation.

Stores should always compare amount_paid (or amount) with the order total before fulfilling, because a manually settled invoice can carry less than was asked for.

Deposit modes

Each project uses one of two ways to match payments. A project created in the dashboard starts in forwarder mode when the server can run it on that network (a fee wallet and a verified factory), so customers pay the exact order amount. Otherwise it starts in unique-amount mode. An admin can switch a project at any time in its settings.

Unique amount Forwarder (address per invoice)
Customer sends 49.907423, exactly 49.90
Customer pays to The project wallet A deposit address made for this invoice
Keys on the server None One fee-payer key, which pays TRX for sweeps
Cost per payment Nothing One sweep, an estimated 11 to 13 TRX, paid by the operator's fee wallet. The operator may charge a network fee in USDT for it
Wrong amount Unmatched, assigned by hand Still belongs to the invoice; partial payments can be topped up
Setup A wallet address A wallet, a funded fee wallet and a verified factory contract

Unique amount flow

 Store backend                 Qirsh                        TRON
 POST /api/v1/invoices  ---->  invoice, amount_due 49.907423
 redirect customer      ---->  /pay/inv_... (QR, TronLink)
                                                          <--- customer sends 49.907423
                               polls TronGrid                  to the project wallet
                               seen        -> confirming
                               solidified  -> paid
 webhook invoice.paid   <----
 fulfil the order              customer goes to success_url

Forwarder flow

 Customer               Deposit address (one per invoice)        Project wallet
 sends 49.90 USDT --->  T... (no contract there yet)
                        Qirsh sees it, waits until it is
                        solidified -> invoice.paid
                                 |
 Qirsh fee wallet -> factory.flush(wallet, fee terms, salt, USDT)
 (pays TRX only)        deploys the forwarder if needed and
                        sends the balance ------------------->   49.90 USDT
                        (minus the network fee, if the            (48.40 if the merchant
                        project has one, to the collector)        pays a 1.50 fee)
                        -> invoice.swept

Deposit addresses, the factory and sweeps

A deposit address is the CREATE2 address of a small forwarder contract (an EIP-1167 clone). It can be computed before anything is deployed ("counterfactual"), so creating an invoice costs nothing on-chain. The project wallet is part of the salt that produces the address, together with the network fee terms (collector, fee token and fee amount). A different wallet or different fee terms give a different address, so whatever lands at a deposit address can only ever be sent to the wallet it was made for, apart from at most the bound fee, once, to the bound collector.

The factory is the contract that deploys forwarders and moves their balance. It has no owner and no admin functions. Anyone may call flush, and it always pays the bound wallet (and the bound fee, if any). Qirsh only uses a factory whose on-chain code matches the committed build in contracts/artifacts/forwarders.json. Details are in the contracts README and the design document.

A sweep is the transaction that moves the funds from a deposit address to the project wallet. Its status appears as sweep.status on the invoice:

sweep.status Dashboard label Meaning
queued queued Waiting to be sent
broadcast sweeping Sent, waiting for the result
swept swept The funds reached the project wallet
failed failed The last attempt failed; it is retried, or someone presses Sweep now
skipped held The balance stays at the address: it is below the automatic minimum, it does not exceed the invoice's unpaid network fee, or the address is from the previous contract version. Sweep now moves it where allowed

sweep is null before anything was queued. Stores fulfil on invoice.paid, never on the sweep: at paid the funds are final and can only go to the project wallet.

The fee wallet

The fee wallet is an ordinary TRON account whose private key the server holds (FEE_PAYER_PRIVATE_KEY or FEE_PAYER_PRIVATE_KEY_FILE, or one key file per network with FEE_PAYER_PRIVATE_KEY_FILE_<NETWORK>). It pays the TRX for energy and bandwidth when deposit addresses are swept. It has no role in any contract. Keep a small TRX float in it and nothing else. See SECURITY.md for what a stolen fee key can and cannot do.

Network fees and the fee collector

The operator can recover the TRX spent on sweeps by charging a network fee in USDT per forwarder invoice. It needs a fee collector: a wallet of the operator's, set with FEE_COLLECTOR_ADDRESS, whose key is not on the server. Without a collector there are no fees.

The fee is set per project (sweep_fee, default SWEEP_FEE_DEFAULT) together with who pays it (sweep_fee_payer): the merchant, by receiving the payment minus the fee, or the customer, by paying the fee on top. The fee, the collector and the project wallet are hashed into each deposit address when the invoice is created. So a deposit address pays at most its bound fee, once, to its bound collector, and everything else only to the project wallet. Later changes to the settings affect new invoices only.

Invoices show the fee in network_fee and what the wallet receives in amount_net. Stores still fulfil on invoice.paid and compare amount_paid with their own price. See Network fees.

Webhooks

The gateway POSTs JSON events to the project's webhook URL, signed with the project's webhook secret in the Qirsh-Signature header.

Event When
invoice.confirming A matching transfer appeared on-chain
invoice.paid The payment is final. The only event that should trigger fulfilment
invoice.expired The invoice expired unpaid
invoice.swept Forwarder mode: the funds reached the project wallet. For accounting only
ping Sent by Send test event in the dashboard or POST /api/v1/webhooks/test

Failed deliveries are retried after 10 s, 30 s, 2 m, 10 m, 30 m, 1 h, 3 h, 6 h, 12 h and 24 h. The webhooks reference has the payload and verification code.

Networks

Network What it is Token contract (USDT)
mainnet Real money TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
nile TRON testnet with a public faucet. Use it first TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf
shasta Older TRON testnet TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs

NETWORK sets the default for new projects. Each project picks its own. Simulated payments are only possible on testnet projects that enable them, and are refused on mainnet.

Edit this page on GitHub