How FTM Games Implement Leaderboards and Achievement Systems
FTM games implement leaderboards and achievement systems by leveraging a combination of on-chain smart contracts for core logic and verifiable data, and off-chain infrastructure for scalability and complex computation. The core of this implementation is the FTM GAMES platform, which utilizes the high-speed, low-cost Fantom Opera blockchain to record player actions immutably. For leaderboards, scores or key performance metrics are written directly to the blockchain as transaction events. A smart contract, often using a mapping data structure, associates a player’s wallet address with their score. This on-chain data is then indexed and queried by a game’s backend server or a decentralized oracle network to generate a sorted list for display in the user interface. Achievements are handled similarly; a smart contract contains the logic for each achievement (e.g., “if walletAddress kills 100 monsters, then unlock achievement X”). When a player’s actions meet the criteria, the contract emits an event or updates a state variable, permanently and transparently recording the accomplishment on the ledger. This hybrid architecture ensures that the most critical data—proof of a score or achievement—is trustless and secure, while the heavy lifting of sorting and displaying global rankings is handled off-chain for performance.
The technical backbone of these systems is the Fantom blockchain itself. With an average block time of around 1 second and transaction fees that are a fraction of a cent, it provides the necessary throughput for real-time gaming interactions. When a player completes a level or achieves a high score, the game client sends a signed transaction to a specific smart contract function. For example, a call to a function like submitScore(uint256 _score) would update that player’s entry. This transaction, once confirmed, is final. The use of smart contracts eliminates any possibility of a central server being manipulated or hacked to alter scores, which is a common vulnerability in traditional web2 games. The transparency of the blockchain means any player can, in theory, verify the entire leaderboard themselves by querying the contract’s public data, fostering a high degree of trust in the system’s fairness.
For achievements, the implementation is even more granular. Developers deploy a smart contract that acts as an achievement registry. This contract has a series of checks for different in-game milestones. Let’s break down a specific example:
- Achievement: “Dragon Slayer”
- Criteria: Defeat a boss enemy with the ID “Dragon_Boss”.
- Smart Contract Logic: The game’s core combat contract, when it processes a “boss defeat” event, checks the defeated boss’s ID. If it matches “Dragon_Boss”, it makes an external call to the achievement contract’s
unlockAchievement(address player, bytes32 achievementId)function. - On-Chain Record: The achievement contract updates a mapping:
mapping(address => mapping(bytes32 => bool)) public hasAchievement;. Setting this totruefor the player and the “Dragon Slayer” achievement ID creates a permanent, on-chain certificate of their feat.
This method ensures that achievements are not just pixels on a screen but are cryptographically secured accomplishments tied directly to the player’s identity (their wallet address).
The Role of Off-Chain Components and Data Indexing
While the trustless foundation is on-chain, a purely on-chain leaderboard for a game with millions of players would be impractical to render in real-time. Sorting through every transaction to find the top scores would be slow and expensive. This is where off-chain indexing services become critical. Platforms like The Graph Protocol are widely used by FTM GAMES developers. An indexer “subgraph” is created that listens for specific events from the game’s smart contracts, such as a ScoreSubmitted event. It then processes and stores this data in a efficiently queryable database.
A game’s frontend (the client you interact with) does not read the leaderboard directly from the blockchain. Instead, it queries the indexed subgraph using GraphQL, a powerful query language. A query to get the top 10 scores might look like this, returning results in milliseconds:
{
playerScores(first: 10, orderBy: score, orderDirection: desc) {
id
playerAddress
score
}
}
The separation of concerns is clear: on-chain for security and verification, off-chain for performance and usability. The following table contrasts the responsibilities of each part of the system:
| Component | Responsibility | Technology Example |
|---|---|---|
| On-Chain Smart Contract | Immutable score/achievement recording, core logic, player-to-data association. | Solidity/Vyper contract on Fantom Opera. |
| Off-Chain Indexer | Listening to contract events, aggregating data, sorting rankings, providing fast API endpoints. | The Graph Protocol Subgraph. |
| Game Client (Frontend) | Displaying the sorted leaderboard and user achievements by querying the indexer. | Unity WebGL, React, Vue.js. |
Advanced Features: Timed Leaderboards and Dynamic Achievements
Sophisticated FTM games implement more than just all-time leaderboards. A common feature is seasonal or weekly leaderboards. This is implemented by adding a time component to the smart contract logic. The submitScore function might require a seasonId parameter. The contract then stores scores mapped to both the player address and the active season. The off-chain indexer can then easily filter and sort scores for a specific season, creating a competitive cycle that encourages repeated engagement. Gas optimization is key here; instead of storing full history on-chain, often only the best score per player per season is stored, with events logging all submissions for the indexer to track.
Achievement systems can also be highly dynamic. Beyond simple “checklist” achievements, some games implement progressive or tiered achievements. For instance, an achievement for “Total Kills” might have bronze, silver, and gold tiers. The smart contract logic for this is more complex. It might maintain a counter for each player’s kills. The achievement contract periodically checks this counter (either on-chain via a function call or off-chain via an oracle) and unlocks the appropriate tier when thresholds (e.g., 100, 500, 1000 kills) are met. This allows for a much deeper and more engaging progression system.
Another advanced concept is composable achievements, where one achievement is a prerequisite for another. This creates a quest-like structure. The contract logic must check the status of prerequisite achievements before granting a new one. For example, the “Master Crafter” achievement might require that the player first has the “Apprentice Crafter” and “Journeyman Crafter” achievements unlocked. This dependency tree is encoded directly into the smart contract’s unlock function, ensuring the integrity of the achievement hierarchy.
Economic and Security Considerations
Implementing these systems on-chain is not without cost. Every score submission and achievement unlock requires a gas fee paid in FTM, the native cryptocurrency of the Fantom network. While these fees are low, game designers must carefully consider the user experience. It would be poor design to require a transaction for every tiny action. Therefore, games often batch operations. Instead of submitting a score after every game, a client might store it locally and submit only the player’s best score for the day. Similarly, achievement progress might be tracked off-chain until a milestone is reached, at which point a single on-chain transaction verifies and unlocks it.
Security is paramount. Smart contracts handling leaderboards and achievements must be rigorously audited. A common attack vector is score manipulation by exploiting game client logic. Since the blockchain only verifies the data sent to it, a hacked client could try to submit a falsely inflated score. Mitigations against this include:
- Server-Side Validation: For more complex games, an off-chain game server can validate the legitimacy of a score before allowing the transaction to be signed and broadcasted.
- Cryptographic Proofs: The game client can generate a cryptographic proof (e.g., a hash of the game session data) that the smart contract can verify, ensuring the score came from a legitimate game session.
- Transaction Signing by a Trusted Verifier: The player’s client sends game results to a trusted backend, which validates them and then signs the transaction to submit the score, preventing direct manipulation by the player’s client.
The economic model can also be integrated. Some games on FTM implement pay-to-submit leaderboards where a small entry fee in FTM is required to submit a score, creating a prize pool for the top players. This is managed entirely transparently by the smart contract, which can automatically distribute rewards at the end of a season based on the final rankings. This adds a powerful incentive layer to the competitive gameplay.
