Skip to content

An orderless full-stack example using the TypeScript SDK for Aptos

License

Notifications You must be signed in to change notification settings

aptos-labs/orderless-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cookie Clicker Aptos - Orderless Transaction DApp

A decentralized cookie clicker game built on Aptos blockchain featuring on-chain clicks, aggregator-based tracking, private entry functions, and orderless transaction processing for optimal performance.

๐Ÿš€ Key Features

Orderless Transaction Processing

  • Rapid Clicking: Click as fast as you want! Multiple click transactions can be submitted simultaneously
  • No Race Conditions: Aptos aggregators handle concurrent modifications safely
  • Parallel Processing: Clicks processed out-of-order without conflicts
  • Better UX: No waiting for previous transaction confirmation

On-Chain Everything

  • Every click is a blockchain transaction using aggregators
  • Concurrent-safe cookie counting with aggregator_v2
  • Private entry functions only (no public functions exposed)
  • True decentralized gaming experience

Game Features

  • Click to Earn: Start with 1 cookie per click
  • Upgrades: Buy multipliers (2x, 5x, 10x clicks)
  • Auto-Clickers: Passive cookie generation (Grandma, Factory, Bank)
  • Prestige System: Reset progress for permanent bonuses

๐Ÿ—๏ธ Architecture

Smart Contract (Move)

  • Language: Move on Aptos
  • Key Feature: Aggregator-based orderless transactions
  • Structure: Private entry functions only
  • Testing: Comprehensive unit tests

Frontend (React + TypeScript)

  • Wallet Integration: Petra, Martian, Pontem
  • Real-time Updates: Event-driven UI updates
  • Optimistic Updates: Immediate feedback
  • Transaction Management: Queue system for parallel processing

๐Ÿ“ Project Structure

cookie-clicker-aptos/
โ”œโ”€โ”€ contracts/
โ”‚   โ”œโ”€โ”€ sources/
โ”‚   โ”‚   โ””โ”€โ”€ cookie_clicker.move      # Main smart contract
โ”‚   โ”œโ”€โ”€ tests/
โ”‚   โ”‚   โ””โ”€โ”€ cookie_clicker_tests.move # Unit tests
โ”‚   โ””โ”€โ”€ Move.toml                     # Move configuration
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/              # React components
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/                   # Game state management
โ”‚   โ”‚   โ”œโ”€โ”€ utils/                   # Aptos integration
โ”‚   โ”‚   โ””โ”€โ”€ App.tsx                  # Main app
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

๐Ÿ› ๏ธ Setup & Deployment

Prerequisites

Smart Contract Deployment

  1. Navigate to contracts directory:

    cd contracts
  2. Initialize Aptos account (if you haven't):

    aptos init --network testnet
  3. Compile the contract:

    aptos move compile
  4. Run tests:

    aptos move test
  5. Deploy to testnet:

    aptos move publish --named-addresses cookie_clicker=default
  6. Note the deployed address and update MODULE_ADDRESS in /frontend/src/utils/aptosClient.ts

Frontend Setup

  1. Navigate to frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Update contract address in src/utils/aptosClient.ts:

    const MODULE_ADDRESS = "YOUR_DEPLOYED_CONTRACT_ADDRESS";
  4. Start development server:

    npm start
  5. Open browser to http://localhost:3000

๐ŸŽฎ How to Play

  1. Connect Wallet: Click "Connect Wallet" and choose your Aptos wallet
  2. Initialize Player: Click "Start Cookie Adventure!" to create your on-chain profile
  3. Click Cookies: Click the big cookie to earn cookies (each click is a blockchain transaction!)
  4. Buy Upgrades: Increase your click multiplier with upgrades
  5. Purchase Auto-Clickers: Generate passive cookie income
  6. Prestige: Reset progress for permanent bonuses when you reach 1M cookies

โšก Orderless Transaction Benefits

Traditional Blockchain Games

  • Wait for each transaction to confirm
  • Race conditions with rapid clicking
  • Sequential processing bottlenecks
  • Poor user experience

Cookie Clicker Aptos

  • โœ… Submit multiple clicks instantly
  • โœ… Aggregators prevent race conditions
  • โœ… Parallel transaction processing
  • โœ… Smooth, responsive gameplay

๐Ÿงช Testing

Smart Contract Tests

cd contracts
aptos move test

Frontend Development

cd frontend
npm test

๐Ÿ“Š Game Economics

Upgrades

  • Double Cursor: 100 cookies โ†’ 2x multiplier
  • Golden Touch: 1,000 cookies โ†’ 5x multiplier
  • Divine Finger: 10,000 cookies โ†’ 10x multiplier

Auto-Clickers

  • Grandma: 50 cookies โ†’ 1 cookie/sec
  • Factory: 500 cookies โ†’ 10 cookies/sec
  • Bank: 5,000 cookies โ†’ 100 cookies/sec

Prestige System

  • Threshold: 1,000,000 cookies
  • Reward: 1 prestige point per 1M cookies
  • Benefit: +1x base click multiplier per prestige point

๐Ÿ”ง Technical Details

Aggregator Usage

// Orderless click processing
entry fun click_cookie(account: &signer) {
    let player_aggs = borrow_global_mut<PlayerAggregators>(addr);
    let click_agg = borrow_global<ClickAggregator>(addr);
    
    // Atomic, concurrent-safe operations
    aggregator::add(&mut player_aggs.total_cookies, click_agg.click_multiplier);
    aggregator::add(&mut player_aggs.lifetime_clicks, 1);
}

Frontend Transaction Queue

// Multiple clicks submitted simultaneously
const handleRapidClick = async () => {
  const clickPromises = Array(clickCount).fill(null).map(() => 
    submitTransaction({
      function: `${MODULE_ADDRESS}::cookie_clicker::click_cookie`,
      arguments: []
    })
  );
  
  // Process all clicks in parallel
  Promise.allSettled(clickPromises);
};

๐Ÿšจ Important Notes

  • Testnet Only: This implementation is configured for Aptos testnet
  • Gas Fees: Each click requires a small amount of APT for gas
  • Wallet Connection: Ensure your wallet is connected to Aptos testnet
  • Contract Address: Update the MODULE_ADDRESS after deployment

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ“œ License

This project is open source and available under the MIT License.

๐ŸŽฏ Future Enhancements

  • Mainnet deployment
  • Additional upgrade tiers
  • Leaderboard system
  • NFT achievements
  • Mobile optimization
  • Sound effects and animations

Experience the future of blockchain gaming with orderless transactions on Aptos! ๐Ÿชโšก

About

An orderless full-stack example using the TypeScript SDK for Aptos

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages