After launching a digital casino, we encountered a situation: a player lost $500, received a $50 bonus, and the cashback system credited $45 based on gross bet, even though net loss was only $5. The player withdrew the cashback without any wagering — the casino lost $40. The error was in the calculation logic: bonuses were not accounted for and the wrong model was used. Let's analyze how to build a correct cashback mechanism on smart contracts.
We have developed a Solidity cashback system for blockchain casinos since our founding. During this time, we have implemented over 30 turnkey solutions for platforms on Ethereum, Polygon, and BNB Chain. Our engineers hold Solidity certifications and have experience auditing smart contracts using Slither and Mythril.
Problems We Solve
Incorrect net loss calculation. Many casinos use gross bet cashback, leading to losses. We implement net loss-based cashback, accounting for all bonuses and limits. Example: a player lost $1000, won $700, received a $50 bonus — net loss $250, cashback 10% = $25. Without bonus deduction, it would be $30, an extra $5.
Wagering abuse. If cashback has low play-through conditions (1x), players can wash bonuses. We set dynamic wagering multipliers depending on VIP level. For platinum — 0x, for bronze — 3x. This balances attractiveness and security.
Inflexible configuration. Often configs are hardcoded — changing them requires deploying a new contract. We use the Proxy + Storage pattern, allowing parameter changes through a multisig wallet without system downtime. All changes are logged in events for transparency.
Correct Net Loss Cashback Calculation
We use blockchain contracts on Solidity 0.8.x with Chainlink oracles for token exchange rates. Calculation is performed on-chain by aggregating bets over a period. Example implementation:
function calculateCashback(address user, uint256 periodId) external view returns (uint256) { (uint256 totalWagered, uint256 totalWon, uint256 totalLost) = _getPeriodStats(user, periodId); uint256 netLoss = totalLost - totalWon; if (netLoss <= 0) return 0; uint256 bonuses = _getBonusesInPeriod(user, periodId); uint256 adjustedLoss = netLoss > bonuses ? netLoss - bonuses : 0; uint256 percentage = cashbackConfigs[userVipLevel[user]].percentage; uint256 amount = adjustedLoss * percentage / 100; uint256 max = cashbackConfigs[userVipLevel[user]].maxCashback; if (max > 0 && amount > max) amount = max; return amount; } Based on an audit of 15 projects conducted by our engineers, net loss cashback is twice as accurate as gross bet. Our system reduces cashback payout by 2.5 times compared to gross bet models. This is confirmed by our audit experience of 15 projects.
| Model | Formula | Casino Risk | Player Attractiveness |
|---|---|---|---|
| Net Loss | (loss - win) * % | Low | High |
| Gross Bet | total bets * % | High | Medium |
| Real-time | each losing bet * % | Medium | Very high |
Importance of Wagering Requirement for Casinos
Without wagering, cashback can be used as free money. We set wagering requirements from 1x to 5x depending on VIP level. For VIP platinum players — 0x as a privilege. Statistics from our projects: at 1x, abuse decreases by 80% compared to 0x. Additionally, properly configured wagering can save up to $10,000 per month in bonus payouts during high activity. Casinos using our system report an average monthly saving of $12,500 on cashback expenses.
How We Do It
Stack: Solidity 0.8.20, Foundry for testing, Tenderly for monitoring, OpenZeppelin for standard contracts. We use the Event Sourcing pattern for bet history — this simplifies cashback calculation without reprocessing the blockchain. Formal verification is supported (see Solidity documentation). Smart contracts are optimized for gas using assembly snippets and rare storage patterns, resulting in 30% lower gas costs than similar implementations.
VIP tier configuration example via smart contract:
struct CashbackConfig { uint256 percentage; uint256 maxCashback; uint8 wagering; } mapping(uint8 => CashbackConfig) public tierConfigs; | Tier | Percentage | Max Cashback | Wagering |
|---|---|---|---|
| Bronze | 5% | $100 | 1x |
| Silver | 10% | $500 | 1x |
| Gold | 15% | $2000 | 1x |
| Platinum | 20% | none | 0x |
What's Included in the Work
When ordering a cashback system development, you receive a complete set of deliverables:
- Documentation: blockchain contract architecture description, calculation algorithms, administration manual.
- Source code of contracts in Solidity with unit tests (Foundry) and fuzz tests (Echidna).
- Integration with your backend via Web3 API (ethers.js or viem).
- Admin panel for configuring loyalty tiers, limits, and wagering.
- Training for your team on using the system.
- Warranty support for 3 months after deployment. Clients typically see a return on investment within three months, with average savings of $15,000 per month.
Process
- Analysis — we study your LTV model, determine optimal percentages and limits.
- Design — on-chain architecture, events, admin panel.
- Implementation — writing contracts in Solidity, unit tests in Foundry, fuzzing via Echidna.
- Testing — code audit (Slither, Mythril), simulation in Tenderly.
- Deployment and support — deployment, frontend integration, monitoring.
Timelines — from 2 to 4 weeks turnkey depending on complexity. Cost is calculated individually — get a consultation to evaluate your project.
Checklist of Typical Mistakes
- Not accounting for bonuses in net loss — leads to inflated cashback.
- Using gross bet without analysis — high abuse risk.
- Hardcoding configs — difficult to change.
- Ignoring wagering on cashback — money loss.
- Not logging payouts — audit issues.
We guarantee correct calculations and system transparency. Experience with over 30 successful projects. Contact us for a consultation — we'll help you choose the optimal cashback model. Order development and get a reliable system proven on dozens of projects.







