v1.6-beta.4 - add mainnet mode + minimal gas-estimate route
Behaviour summary
1. Network mode (backend/src/hederaClient.js + backend/src/utils/config.js)
HEDERA_NETWORKenv var added; defaults to"testnet"(so testnet mode is preserved exactly as before for any deployment that doesn't set the variable).makeHederaClient(operatorId, operatorKey, network?):- When
network === "testnet"→Client.forTestnet() - When
network === "mainnet"→Client.forMainnet() - When
networkis anything else (typo, case mismatch) → explicit error:Unknown Hedera network ... Set HEDERA_NETWORK to "testnet" or "mainnet".
- When
- New
getActiveNetwork()andisMainnet()helpers.isMainnet()is consumed byindex.jsboot path:testnetmode → logs🧪 Hedera client running in TESTNET modemainnetmode → logs a⚠️warning that the deployment is signing REAL transactions for account<operator>
- Backwards-compat: every existing caller of
getHederaClient()keeps the singleton behaviour. The only contract change is the log line.
2. Gas estimator (backend/src/utils/gasEstimate.js)
TINYBARS_PER_HBAR = 100_000_000nexported.currentFeeSchedule()walks the mirror-node/api/v1/network/feespayload'stransaction_fee_schedulearray and matches on Hedera'snamefield (post-0.46 mirror-node release) to pick the right bucket per transaction type. Falls back to the lowest-priced bucket when no name match exists.estimateBatchGas({ batchCount, safetyMargin, tinybarCeiling, mirrorNodeUrl, timeoutMs, usdPerHbar })returns:{ tinybarsTotal, hbarTotal, usdEstimate, perBatchTinybars, safetyMargin, tinybarCeiling, capped, // true → clamped to ceiling network, // "testnet" | "mainnet" source, // "live" (mirror node returned data) or "fallback" timestamp // mirror-node payload timestamp, if available }- Defaults:
safetyMargin = 1.1(+10%),tinybarCeiling = 5_000_000n tinybar ≈ 0.05 HBAR. Mirror node outing falls back to a published-historical estimate (10_000ntinybar on mainnet,1_000non testnet) so the endpoint is always 200-OK.
3. HTTP route (backend/src/routes/gasEstimate.js)
GET /api/gas-estimate?batchCount=N&safetyMargin=...&tinybarCeiling=...&usdPerHbar=...- All query params optional; refers to defaults from
estimateBatchGas(). - Validates input: non-integer batch counts and out-of-range margins → HTTP
400 { ok: false, error: ..., code: "gas_estimate_invalid_input" }. DB / mirror outage → HTTP200withsource: 'fallback'(the API is best-effort; the user can still submit a batch). - Returns bigints as decimal strings to preserve precision across JSON.
4. Booting (backend/src/index.js)
- After
getHederaClient()init, the server announces which network is active. This is a singleconsole.warn/console.logdifferentiated byisMainnet(). Maintaining existingtry/catch/process.exit(1)flow.
5. Documentation (backend/.env.example)
- Adds
HEDERA_NETWORK=testnetblock with proactive commentary on:- default + safety
- mainnet requirement (mainnet-funded operator + mainnet mirror node URL).
this improvement project is proposed by @arcgod-design
You can support AgroDex project for Indonesian agriculture in here https://github.com/sponsors/daviddprtma