Hosting guide
Qirsh is one Node.js process and one SQLite file. This guide puts it on a Linux server behind HTTPS, with backups, upgrades and monitoring. Every environment variable is listed in Configuration.
Requirements
- A Linux server with 1 vCPU and 512 MB of RAM or more. One instance handles thousands of invoices per hour.
- Docker with the compose plugin, or Node.js 22 or later.
- A domain name for the gateway, for example
pay.example.com. Customers see it on the checkout. - Outbound HTTPS to TronGrid (
api.trongrid.io,nile.trongrid.io) and to your stores' webhook endpoints. - A free TronGrid API key from https://www.trongrid.io for mainnet (
TRONGRID_API_KEY). Without one you will hit rate limits.
Configure
git clone https://github.com/AQaddora/qirsh
cd qirsh
cp .env.example .env
openssl rand -base64 18 # a password for ADMIN_PASSWORDSet at least:
ADMIN_EMAIL=you@example.com
ADMIN_PASSWORD=<generated>
PUBLIC_URL=https://pay.example.com
TRUST_PROXY=true
TRONGRID_API_KEY=<your key>
NETWORK=nilePUBLIC_URL is used to build every checkout_url, and an https:// value also makes the session cookie Secure. TRUST_PROXY=true makes rate limiting see the real client IP from X-Forwarded-For. Set it only when the gateway is reachable through your proxy and nowhere else.
Start on nile. Move a store to mainnet after the checks in Testing pass.
Run with Docker
docker compose up -d --build
docker compose logs -f qirsh
curl -s http://127.0.0.1:8080/healthWhat the bundled docker-compose.yml does:
- builds the image from the
Dockerfile(Node 22, runs as thenodeuser); - reads
.env; - stores the database in the named volume
qirsh-data, at/data/qirsh.db; - publishes port 8080 on
127.0.0.1only. Keep it that way. The API key travels in theAuthorizationheader and must never cross the internet over plain HTTP, and withTRUST_PROXY=truea public port would let clients fakeX-Forwarded-For; - has a health check that calls
/healthevery 30 seconds.
The admin CLI runs inside the container:
docker compose exec qirsh node dist/cli.js list-usersRun with Node and systemd
Create a user and install the app:
sudo useradd --system --create-home --home-dir /opt/qirsh --shell /usr/sbin/nologin qirsh
sudo -u qirsh git clone https://github.com/AQaddora/qirsh /opt/qirsh/app
cd /opt/qirsh/app
sudo -u qirsh npm ci
sudo -u qirsh npm run build
sudo -u qirsh npm prune --omit=dev
sudo install -d -o qirsh -g qirsh -m 700 /var/lib/qirsh
sudo install -o root -g qirsh -m 640 .env.example /etc/qirsh.envEdit /etc/qirsh.env as in Configure, plus:
DATABASE_PATH=/var/lib/qirsh/qirsh.db
HOST=127.0.0.1
PORT=8080better-sqlite3 downloads a prebuilt binary during npm ci. If none exists for your platform it compiles one, which needs python3, make and g++.
Create /etc/systemd/system/qirsh.service:
[Unit]
Description=Qirsh USDT payment gateway
After=network-online.target
Wants=network-online.target
[Service]
User=qirsh
Group=qirsh
WorkingDirectory=/opt/qirsh/app
EnvironmentFile=/etc/qirsh.env
ExecStart=/usr/bin/node dist/index.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictSUIDSGID=true
LockPersonality=true
ReadWritePaths=/var/lib/qirsh
[Install]
WantedBy=multi-user.targetProtectHome=true hides /home, which is fine because the app lives in /opt. If you use forwarder mode with FEE_PAYER_PRIVATE_KEY_FILE, keep the key file outside the app directory, readable only by qirsh (for example /etc/qirsh/fee_payer.key, mode 600).
sudo systemctl daemon-reload
sudo systemctl enable --now qirsh
journalctl -u qirsh -fThe admin CLI needs the same environment:
cd /opt/qirsh/app
sudo -u qirsh node --env-file=/etc/qirsh.env dist/cli.js list-usersHTTPS with nginx and certbot
/etc/nginx/sites-available/qirsh:
server {
listen 80;
server_name pay.example.com;
client_max_body_size 128k;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 30s;
}
}sudo ln -s /etc/nginx/sites-available/qirsh /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d pay.example.comcertbot adds the TLS listener and the redirect from HTTP, and renews the certificate automatically. The gateway's request body limit is 64 KB, so client_max_body_size 128k is plenty.
Caddy instead of nginx
Caddy gets and renews certificates by itself:
pay.example.com {
reverse_proxy 127.0.0.1:8080
}Backups
The database holds projects, users, API key hashes, webhook secrets, invoices, transfers, webhook logs and the activity log. The money is on-chain and does not depend on it, but losing it means losing your records and every project's configuration.
The database runs in WAL mode, so copy it with SQLite's backup API, not with cp.
Node install, with the sqlite3 command line tool:
sqlite3 /var/lib/qirsh/qirsh.db ".backup '/var/backups/qirsh/qirsh-$(date +%F).db'"Docker (the image has no sqlite3, so use the bundled driver):
docker compose exec qirsh node -e \
"require('better-sqlite3')('/data/qirsh.db').backup('/data/backup.db').then(()=>console.log('ok'))"
docker compose cp qirsh:/data/backup.db ./backups/qirsh-$(date +%F).dbRun it daily from cron, for example:
15 3 * * * sqlite3 /var/lib/qirsh/qirsh.db ".backup '/var/backups/qirsh/qirsh-$(date +\%F).db'" && find /var/backups/qirsh -name '*.db' -mtime +30 -deleteBackups contain webhook secrets and, in single-store mode, nothing else secret (API keys are hashed). Store them encrypted, and never in the same place as a fee-payer key file.
To restore: stop the gateway, put the backup file at DATABASE_PATH (and delete any -wal and -shm files next to it), start the gateway. Test a restore on another machine now and then. A backup you have never restored is a guess.
If the database is lost
- Unique-amount projects: the funds are already in the project wallets. Recreate the projects (with new API keys and webhook secrets) and reconcile open orders against the wallets on Tronscan.
- Forwarder projects: payments may be waiting at deposit addresses. Each address can be recomputed from its invoice id, the factory and the project wallet, and flushed to the wallet, without the database:
npm run admin -- recover-forwarder --network mainnet --factory T... --destination <project wallet> \
--invoices-file invoice-ids.txt # add --send to flushAddresses created with a network fee also need the fee terms: add --collector T... --fee 1.5 with the project's fee, or rely on the defaults (FEE_COLLECTOR_ADDRESS and SWEEP_FEE_DEFAULT). Use --fee 0 for addresses without a fee. A wrong guess derives a different, empty address and sends nothing. See Network fees.
Invoice ids are in your stores' orders, webhook logs and checkout URLs. See the contracts README for a manual flush on Tronscan.
Upgrades
- Read CHANGELOG.md for the versions you are skipping.
- Back up the database.
- Update and restart.
Docker:
git pull
docker compose up -d --buildNode:
cd /opt/qirsh/app
sudo -u qirsh git pull
sudo -u qirsh npm ci && sudo -u qirsh npm run build && sudo -u qirsh npm prune --omit=dev
sudo systemctl restart qirshDatabase migrations run automatically at start. They only move forward, so to roll back, check out the previous version and restore the backup you took in step 2. Invoices created in between are lost from the database (not on-chain), so roll back quickly or not at all.
If you use forwarder mode and upgrade from a version without network fees, deploy a v2 factory afterwards (deploy-factory --network <n> --force) and set the new FORWARDER_FACTORY_<NETWORK>. See the operator guide.
Monitoring
GET /health is public:
{
"ok": true,
"watcher": { "ok": true, "last_poll_at": "2026-12-05T18:00:10.000Z", "last_error": null, "catching_up": false, "deposits_unreconciled": 0 },
"sweeper": { "enabled": true, "ok": true, "queued": 0, "in_flight": 0, "failed": 0, "held": 1 }
}- It answers
200while the chain watcher is healthy and503when polling has been failing for more than five poll intervals (at least two minutes).watcher.last_errorsays why, most often a TronGrid rate limit. Point your uptime monitor at it. catching_up: truemeans the watcher is working through a backlog after downtime or a burst.- The
sweeperobject reports forwarder sweeps. It never changes the HTTP status: a stuck sweep loses no payments. Alert onfailedgreater than zero and on a fee wallet level ofloworempty(dashboard, Fee wallet tab, ornpm run admin -- fee-wallet).
Also watch the dashboard for unmatched transfers and failed webhooks. Logs are JSON lines (pino) on stdout, with the level set by LOG_LEVEL.
A static project website
The landing page and docs can also be published without a running gateway, for example on Cloudflare Pages or GitHub Pages:
SITE_URL=https://example.org SIGN_IN_URL=https://pay.example.org/admin npm run site:exportThis writes dist-site/ with index.html, docs/*.html, the assets and a _headers file with the same security headers the gateway sends. Links to the legal pages point at the templates in the repository, because those pages belong to whoever runs an instance. Set LEGAL_PAGES=true to export them filled from the usual OPERATOR_* variables instead.
Scaling
Run one instance per database. The watcher, the webhook outbox and the sweeper assume a single writer, and SQLite is a single file. If you need separate mainnet and testnet environments, run two instances with two databases (and, in forwarder mode, two fee keys).
Security checklist
SECURITY.md has the full operator checklist. The short version: HTTPS only, the port bound to localhost, ALLOW_SIMULATION=false and no simulation on mainnet projects, TRUST_PROXY=true only behind your own proxy, daily backups, and in forwarder mode a dedicated fee key per network with a small balance.