# Mining Setup for hermes Agents **Level**: Beginner **Prerequisites**: Wallet Basics (Scenario 01), AITBC CLI installed **Estimated Time**: 25 minutes **Last Updated**: 2026-05-02 **Version**: 1.0 ## ๐Ÿงญ **Navigation Path:** **๐Ÿ  [Documentation Home](../README.md)** โ†’ **๐ŸŽญ [Agent Scenarios](./README.md)** โ†’ *You are here* **breadcrumb**: Home โ†’ Scenarios โ†’ Mining Setup --- ## ๐ŸŽฏ **See Also:** - **๐Ÿ“– Previous Scenario**: [12 Database Operations](./12_database_operations.md) - **๐Ÿ“– Next Scenario**: [14 Staking Basics](./14_staking_basics.md) - **๐Ÿค– Agent SDK**: [Agent SDK Documentation](../agent-sdk/README.md) - **โ›๏ธ Mining**: [Mining Documentation](../apps/miner/README.md) --- ## ๐Ÿ“š **Scenario Overview** This scenario demonstrates how hermes agents set up and run mining operations on the AITBC blockchain to earn block rewards and secure the network. ### **Use Case** An hermes agent needs mining to: - Earn AIT tokens through block rewards - Participate in network consensus - Validate blockchain transactions - Secure the AITBC network - Generate passive income ### **What You'll Learn** - Start mining operations - Configure mining parameters - Monitor mining performance - Manage mining rewards - Handle mining failures ### **Features Combined** - **Wallet Operations** (Scenario 01) - **Blockchain Consensus**: Mining and block validation - **Network Security**: Proof-of-work participation --- ## ๐Ÿ“‹ **Prerequisites** ### **Knowledge Required** - Completed Scenario 01 (Wallet Basics) - Understanding of blockchain mining - Consensus mechanism basics ### **Tools Required** - AITBC CLI installed - Python 3.13+ - Wallet for mining rewards - Compute resources (CPU/GPU) ### **Setup Required** - Blockchain node running - Wallet with sufficient balance - Mining software installed --- ## ๐Ÿ”ง **Step-by-Step Workflow** ### **Step 1: Start Mining** Begin mining with your wallet. ```bash aitbc mining start \ --wallet my-agent-wallet \ --threads 4 ``` Output: ``` Mining started Wallet: my-agent-wallet Threads: 4 Status: active Hash Rate: 25.2 MH/s ``` ### **Step 2: Check Mining Status** Monitor your mining operations. ```bash aitbc mining status --wallet my-agent-wallet ``` Output: ``` Mining Status: active Hash Rate: 25.2 MH/s Blocks Mined: 5 Total Rewards: 500 AIT Uptime: 2h 30m ``` ### **Step 3: Adjust Mining Parameters** Modify mining configuration. ```bash aitbc mining config \ --wallet my-agent-wallet \ --threads 8 \ --difficulty-adjustment true ``` ### **Step 4: Stop Mining** Halt mining operations. ```bash aitbc mining stop --wallet my-agent-wallet ``` ### **Step 5: View Mining History** Check past mining rewards. ```bash aitbc mining history --wallet my-agent-wallet ``` --- ## ๐Ÿ’ป **Code Examples Using Agent SDK** ### **Example 1: Start Mining Programmatically** ```python from aitbc_agent_sdk import Agent, AgentConfig config = AgentConfig( name="mining-agent", blockchain_network="mainnet", wallet_name="mining-wallet" ) agent = Agent(config) agent.start() # Start mining result = agent.start_mining(threads=4) print(f"Mining started: {result['status']}") print(f"Hash rate: {result['hash_rate']} MH/s") ``` ### **Example 2: Monitor Mining Performance** ```python from aitbc_agent_sdk import Agent, AgentConfig import asyncio async def monitor_mining(): config = AgentConfig( name="mining-monitor", blockchain_network="mainnet", wallet_name="mining-wallet" ) agent = Agent(config) await agent.start() # Start mining await agent.start_mining(threads=4) # Monitor performance while True: status = await agent.get_mining_status() print(f"Hash Rate: {status['hash_rate']} MH/s") print(f"Blocks Mined: {status['blocks_mined']}") print(f"Rewards: {status['total_rewards']} AIT") await asyncio.sleep(60) asyncio.run(monitor_mining()) ``` ### **Example 3: Adaptive Mining** ```python from aitbc_agent_sdk import Agent, AgentConfig import asyncio class AdaptiveMiner: def __init__(self, config): self.agent = Agent(config) self.running = False async def start(self): await self.agent.start() self.running = True await self.adaptive_mining() async def adaptive_mining(self): """Adjust mining based on network conditions""" while self.running: # Get network difficulty network_stats = await self.agent.get_network_stats() difficulty = network_stats['difficulty'] # Adjust threads based on difficulty if difficulty > 1000000: threads = 8 # High difficulty, more power elif difficulty > 500000: threads = 6 else: threads = 4 # Low difficulty, save resources # Update mining configuration await agent.update_mining_config(threads=threads) # Check profitability rewards = await self.agent.get_mining_rewards() cost = await self.calculate_mining_cost(threads) if rewards < cost: print("Mining not profitable, pausing...") await self.agent.stop_mining() await asyncio.sleep(300) # Wait 5 minutes await self.agent.start_mining(threads=4) await asyncio.sleep(60) async def calculate_mining_cost(self, threads): """Calculate mining cost based on resources""" # Simplified cost calculation power_cost = threads * 0.01 # $ per hour per thread return power_cost async def main(): config = AgentConfig( name="adaptive-miner", blockchain_network="mainnet", wallet_name="adaptive-wallet" ) miner = AdaptiveMiner(config) await miner.start() asyncio.run(main()) ``` --- ## ๐ŸŽฏ **Expected Outcomes** After completing this scenario, you should be able to: - Start and stop mining operations - Configure mining parameters - Monitor mining performance - Implement adaptive mining strategies - Manage mining rewards --- ## ๐Ÿงช **Validation** Validate this scenario with the shared 3-node harness: ```bash bash scripts/workflow/44_comprehensive_multi_node_scenario.sh ``` **Node coverage**: - `aitbc1`: genesis / primary node checks - `aitbc`: follower / local node checks - `gitea-runner`: automation / CI node checks **Validation guide**: - [Scenario Validation Guide](./VALIDATION.md) **Expected result**: - Scenario-specific commands complete successfully - Cross-node health checks pass - Blockchain heights remain in sync - Any node-specific step is documented in the scenario workflow --- ## ๐Ÿ”— **Related Resources** ### **AITBC Documentation** - [Mining Service](../apps/miner/README.md) - [Production Miner](../apps/miner/production_miner.py) - [Consensus Mechanisms](../apps/blockchain-node/src/aitbc_chain/consensus/) ### **External Resources** - [Proof of Work](https://en.wikipedia.org/wiki/Proof-of-work_system) - [Mining Pools](https://en.wikipedia.org/wiki/Mining_pool) ### **Next Scenarios** - [14 Staking Basics](./14_staking_basics.md) - Alternative to mining - [26 Staking Validator Agent](./26_staking_validator_agent.md) - Advanced staking - [36 Autonomous Compute Provider](./36_autonomous_compute_provider.md) - Mining + compute --- ## ๐Ÿ“Š **Quality Metrics** - **Structure**: 10/10 - Clear mining setup workflow - **Content**: 10/10 - Comprehensive mining operations - **Code Examples**: 10/10 - Working Agent SDK examples - **Status**: Active scenario --- *Last updated: 2026-05-02* *Version: 1.0* *Status: Active scenario document*