Skip to main content

Smart Contracts Overview

Candy Mountain Trail leverages smart contracts for trustless trading, scoring, and rewards.

Contract Architecture

CandyRoadsDEX

The main decentralized exchange contract handling all in-game trading.

Key Features:

  • Automated Market Making (AMM) for resource pairs
  • Dynamic pricing based on supply/demand
  • Location-based scarcity multipliers
  • Profession-specific trading bonuses

Main Functions:

// Buy resources with ETH
function buyResource(ResourceType resource, uint256 amount)

// Sell resources for ETH
function sellResource(ResourceType resource, uint256 amount)

// Trade between resources
function swapResources(ResourceType from, ResourceType to, uint256 amount)

GameRegistry

Manages player profiles, scores, and achievements.

Key Features:

  • On-chain player registration
  • Score verification and storage
  • Achievement NFT minting
  • Leaderboard management

ResourceNFT

ERC-1155 contract for special resource items.

Token Types:

  • Legendary Candy (Rare drops)
  • Golden Unicorn Feed (Premium transport)
  • Mystic Magic Dust (Special abilities)
  • Reinforced Wagon Parts (Durability bonus)

Trading Mechanics

Price Calculation

Price = Base Price × Location Multiplier × Scarcity Factor × Profession Modifier

Location Multipliers

  • Trading Post: 1.0x
  • Lollipop Forest: 1.2x
  • Gummy Bear Plains: 1.5x
  • Licorice Desert: 2.0x
  • Rainbow River: 2.5x
  • Candy Mountain: 3.0x

Profession Bonuses

  • Merchant: 15% better prices
  • Explorer: 10% resource finding bonus
  • Survivor: 20% efficiency bonus

Integration Guide

Connecting Your Wallet

// Connect to MetaMask or other Web3 wallet
const accounts = await ethereum.request({
method: 'eth_requestAccounts'
});

Reading Contract Data

// Get current resource prices
const candyPrice = await dexContract.getResourcePrice(CANDY);
const feedPrice = await dexContract.getResourcePrice(UNICORN_FEED);

Making Transactions

// Buy candy with ETH
await dexContract.buyResource(
CANDY,
ethers.utils.parseEther("10"),
{ value: ethers.utils.parseEther("0.1") }
);

Security Considerations

Audited Contracts

All contracts have been audited for:

  • Reentrancy protection
  • Integer overflow/underflow
  • Access control
  • Economic exploits

Best Practices

  • Always check gas prices before transactions
  • Verify contract addresses before interaction
  • Start with small amounts when testing
  • Keep private keys secure

Contract Addresses

Mainnet (Coming Soon)

  • CandyRoadsDEX: 0x...
  • GameRegistry: 0x...
  • ResourceNFT: 0x...

Testnet (Sepolia)

  • CandyRoadsDEX: 0x...
  • GameRegistry: 0x...
  • ResourceNFT: 0x...

Developer Resources

  • GitHub Repository
  • Contract ABIs (Coming Soon)
  • Integration Examples (Coming Soon)
  • API Documentation (Coming Soon)

Need help? Join our Developer Telegram!