A React and Vite app with a small Node.js backend: accounts, a signed offerwall link, a verified postback endpoint and a live balance. The browser never sees a Moonetix secret.
Moonetix is an affiliate network: your users earn your own currency by completing offers, and you earn per completed offer. A Vite app is static files, so something has to hold the link hash salt and the postback key. Here that is server/, about 500 lines on node:http and node:sqlite, with no npm packages.
To run it you need your Moonetix App ID and keys: see Get your keys.
- A clean split.
src/is React 19 and talks to/apionly.server/signs links for the session user and verifies postbacks.npm run check:bundlefails the build if the salt or key shows up anywhere indist/. - Postbacks that cannot pay twice.
transaction_idis the primary key, credit and balance change run in oneBEGIN IMMEDIATEtransaction, and a reversal takes back what was stored. The tests fire 20 copies of one postback at once and see one credit. - Production details done. Hashed session tokens in HttpOnly SameSite cookies, scrypt passwords, rate-limited sign-up and login, JSON-only writes with an Origin check, and a Content Security Policy that allows only
wall.moonetix.com.
sequenceDiagram
actor U as User
participant R as React app (browser)
participant S as Node.js server
participant W as Moonetix offerwall
U->>R: Logs in
R->>S: GET /api/offerwall-link (session cookie)
S->>S: User from the session, HMAC with the link salt
S-->>R: { url }
R->>W: data-moonetix-open link (pop-up), or iframe
U->>W: Completes an offer
W->>S: GET /moonetix/postback (status 1 or 2)
S->>S: Verify HMAC, store once per transaction_id
S-->>W: 200
R->>S: GET /api/me when the tab is visible again
S-->>R: New balance and history
Node.js 22.13 or later.
git clone https://github.com/moonetix/offerwall-react-vite.git
cd offerwall-react-vite
npm ci
cp .env.example .env # App ID, link hash salt, postback secret key
npm run dev # API on :8787, Vite on :5173 with /api proxiedProduction:
npm run build && npm run check:bundle
COOKIE_SECURE=true npm start # serves dist/ and the API on PORT, behind your https proxySave this postback URL on the Postback page of your Moonetix dashboard:
https://YOUR_DOMAIN/moonetix/postback?tx={transaction_id}&user={user_id}&reward={reward}&status={status}&offer={offer_name}&hash={hash}
| Variable | Required | Default | What it is |
|---|---|---|---|
MOONETIX_APP_ID |
yes | none | App ID, under Offerwalls, your offerwall, Integration. |
MOONETIX_LINK_SALT |
yes | none | Link hash salt, same place. Server only. |
MOONETIX_POSTBACK_KEY |
yes | none | Postback secret key, from the Postback page. Server only. |
MOONETIX_CREDIT_TEST_POSTBACKS |
no | false |
true credits dashboard test postbacks (test_ transaction IDs). |
COOKIE_SECURE |
no | true |
false only for plain http on your machine. .env.example sets false. |
PORT |
no | 8787 |
API port, and the app port for npm start. |
HOST |
no | 127.0.0.1 |
Listen address. Use 0.0.0.0 in a container. |
DATABASE_PATH |
no | ./data.sqlite |
SQLite file. |
The server reads .env from the repo root if it exists, otherwise the real environment. A missing key is logged as MOONETIX_APP_ID is not set. See .env.example. at start.
Never give these a VITE_ prefix: Vite inlines VITE_ variables into the JavaScript it ships.
- Sign-up asks for an email, a password of 10 or more characters and confirmation that the user is 16 or older. Emails are unique regardless of case.
- The session cookie holds a random token. The database stores only its SHA-256, so a leaked database does not leak sessions.
GET /api/offerwall-linkreads the user from the cookie, never from the query, and returns the link withCache-Control: private, no-store. TheuseOfferwallLinkhook drops a link fetched for a previous user.- The Earn button is a normal link with
data-moonetix-open. Whenembed.jshas loaded, it opens the offerwall in a pop-up over the page; otherwise the link opens the offerwall itself. "Show offers on this page" swaps in an iframe instead. GET /moonetix/postbackaccepts each signed parameter exactly once and checks the HMAC-SHA256 oftx:user:reward:statusin constant time (403 if wrong). Signed but unusable values get 400.test_postbacks are logged and answered 200.- In one transaction: status 1 inserts the transaction and adds the reward once; status 2 subtracts the stored amount from the stored user once; a reversal of an unknown transaction is stored with amount 0 so a late credit cannot pay. The answer is 200 only after the commit, 500 on errors so Moonetix retries.
- The React app reloads
/api/mewhen the tab becomes visible again, which is when users come back from the offerwall.
The iframe and pop-up only load on https pages of the website you registered for the app. On http://localhost they stay blank, which is expected: open the link in a new tab while you develop.
- Secrets are read from the environment by
server/only.src/never imports fromserver/. - The hash is the first check on a postback, with
crypto.timingSafeEqualbehind a length check. - Only
{reward}is signed.{offer_name}is shown in the history but never decides an amount. - Writes must be
application/jsonand same-origin, which a cross-site form cannot send. Sessions areHttpOnly; SameSite=Lax, andSecurein production. - Balances are integers in millionths of a coin. A reversal can take a balance below zero; say so in your terms.
- Reward only completed offers, never joins, invites, likes or reviews. Users must be 16 or older.
- The rate limiter is in memory, which suits one process. Behind several instances, move it to your proxy or Redis.
npm testNo network and no packages needed. The tests start the real server on a random port with an in-memory database and check sign-up rules, rate limits, CSRF defenses, logout, that the signed link equals the Moonetix link for the session user, credits, retries, decimals, 20 parallel copies, reversals, a reversal before its credit, unknown users, test_ postbacks, tampered and wrongly signed postbacks, repeated parameters, the CSP header and path traversal.
By hand:
TX=local_1 U=1 R=150 S=1
HASH=$(printf '%s' "$TX:$U:$R:$S" | openssl dgst -sha256 -hmac "$MOONETIX_POSTBACK_KEY" | sed 's/^.* //')
curl -i "http://127.0.0.1:8787/moonetix/postback?tx=$TX&user=$U&reward=$R&status=$S&hash=$HASH"For the whole set of edge cases, run postback-tester against npm run dev. It signs postbacks exactly like Moonetix and sends a credit and its retry, three kinds of reversal, four forged or unsigned requests and five parallel copies of one credit. Its transaction IDs start with test_, so set MOONETIX_CREDIT_TEST_POSTBACKS=true in .env while it runs, sign up once so user 1 exists, and keep MOONETIX_POSTBACK_KEY set in your shell as for the curl above:
npx github:moonetix/postback-tester --preset moonetix \
'http://127.0.0.1:8787/moonetix/postback?tx={transaction_id}&user={user_id}&reward={reward}&status={status}&offer={offer_name}&hash={hash}' --user 1With Moonetix, once the server is reachable over https:
- Offerwalls, your offerwall, Integration: under Integration status, Check a link and Test a link for user ID
1must match the link the app shows. - Click Send a test postback, or use the Postback page. The server logs the test and answers 200. Every attempt is listed under Reports, Postbacks.
- Open the offerwall from a normal home or mobile connection. VPNs, proxies and data center networks see a block page.
| What you see | Why, and the fix |
|---|---|
Earn shows Offerwall not configured. (500 from /api/offerwall-link) |
MOONETIX_APP_ID or MOONETIX_LINK_SALT is missing. Check the warning printed at start. |
Sign-in works, then every call says Not signed in. |
COOKIE_SECURE is true on plain http, so the browser drops the cookie. Serve over https, or set COOKIE_SECURE=false locally. |
Bad request. on sign-up or login from your own client |
Writes must be Content-Type: application/json and same-origin. |
Too many attempts. Try again later. |
The in-memory rate limit on sign-up and login. It resets with time or a restart. |
npm start shows Run npm run build first. |
dist/ is missing. Run npm run build. |
Postback answers 403 |
Wrong MOONETIX_POSTBACK_KEY, a changed value, or a signed parameter sent twice. 400 means signed but unusable values (bad status or reward). |
- Academy: How to add an offerwall to a Next.js or React app
- Academy: Add a floating Earn button to any website
- Docs: Offerwall link, Postbacks, Credits and reversals, Testing
- Moonetix for web apps and websites
- Tools: offerwall link builder, postback hash checker
Get your App ID and keys: sign up free at https://moonetix.com/register?from=github-offerwall-react-vite
Every publisher application is reviewed by hand. Once you are approved, add your site, set your currency, and paste the keys into .env.
| Repository | What it covers |
|---|---|
| awesome-offerwalls | Curated list of offerwall networks, tools and guides |
| offerwall-postback-handlers | Postback handlers in PHP, Node.js, Python and Java |
| offerwall-nextjs-starter | Next.js App Router starter |
| telegram-mini-app-offerwall | Telegram Mini App with server-side initData checks |
| discord-rewards-bot | Discord bot with an economy and offerwall rewards |
| moonetix-offerwall-wordpress | WordPress plugin |
| moonetix-android-sdk | Android SDK |
| moonetix-ios-sdk | iOS SDK |
| moonetix-flutter | Flutter plugin |
| moonetix-react-native | React Native package |
| moonetix-unity | Unity package |
| offerwall-laravel | Laravel integration |
| offerwall-django | Django integration |
| offerwall-express | Express integration |
| offerwall-vue-nuxt | Vue and Nuxt integration |
| offerwall-firebase-functions | Cloud Functions for Firebase with Firestore |
| offerwall-supabase | Supabase Edge Functions with Postgres |
| rewards-site-starter | Rewards (GPT) site starter in PHP and SQLite |
| offerwall-unity-example | Unity sample game |
| offerwall-godot | Godot integration |
| offerwall-html5-game | HTML5 game integration |
| offerwall-flutter-example | Flutter sample app |
| offerwall-react-native-example | React Native sample app |
| offerwall-chrome-extension | Chrome extension |
| offerwall-electron | Electron desktop app |
| postback-tester | Sends signed test postbacks and catches double credits, missed reversals and forged requests |
| signup-guard | Sign-up risk checks for Node.js and PHP: disposable emails, datacenter and Tor IPs |
| datacenter-ip-ranges | Daily cloud, Tor and iCloud Private Relay IP ranges from official feeds |
| offerwall-fraud-playbook | Fraud playbook for offerwall and rewards publishers, with tested code |
| reward-economy-kit | Integer points math: payout to points, bonuses, reversals, cash-out pricing |
| referral-engine | Referral codes, attribution and a clawback-safe commission ledger |
| gamification-kit | Streaks, XP levels, quests and leaderboards that survive time zones and DST |
| affiliate-postback-macros | Postback macros and signatures of tracking platforms and offerwalls |
| country-tiers | Tier 1, 2 and 3 countries as JSON and CSV, with helpers in JavaScript, PHP and Python |
MIT. See LICENSE.