# $CODES AI Agent Mining Skill

This skill file is designed for terminal-capable AI agents such as OpenClaw, Hermes, Claude, or similar autonomous coding agents.

The goal is to help an AI agent install, configure, run, monitor, and restart the $CODES miner on a VPS or GPU machine.

## Project Overview

$CODES is a mine-to-mint ERC20 token on Ethereum Mainnet.

- Token: $CODES
- Network: Ethereum Mainnet
- Chain ID: 1
- CODES contract: `0xdAeEB910888e3613638C6a9b71691C72B2e7DD36`
- Marketplace contract: `0xe6dd327bc1c8A4D49cc11fe2c1AF27D66E1223Ac`
- Mining reward: `1000 $CODES` per accepted valid block
- Marketplace lot size: `1000 $CODES`
- Marketplace burn on sale: `10%`
- Buyer receives: `90%` of the listed $CODES amount

## Official Miner Repositories

CPU miner:

```txt
https://github.com/404-Agent/codes-miner
```

GPU miner:

```txt
https://github.com/404-Agent/code-miner-gpu
```

## AI Agent Objective

The AI agent should:

1. Install the required dependencies.
2. Clone the correct miner repository.
3. Configure the `.env` file.
4. Run the miner.
5. Monitor miner logs.
6. Restart the miner if it stops.
7. Keep the miner running safely.
8. Never expose private keys.

## Important Safety Rules

The AI agent must follow these rules at all times:

1. Never print or reveal `MINER_PRIVATE_KEY`.
2. Never send the private key to any external service.
3. Never overwrite `.env` unless explicitly instructed by the user.
4. Always verify the contract address before mining.
5. Always use Ethereum Mainnet with `CHAIN_ID=1`.
6. Do not change mining difficulty.
7. Do not withdraw contract treasury funds.
8. Do not modify marketplace contracts.
9. Do not transfer mined $CODES unless explicitly instructed by the user.
10. Use a dedicated mining wallet only.

## Recommended VPS Requirements

For CPU mining:

- Ubuntu 22.04 or newer
- Node.js 20+
- Rust toolchain
- At least 2 CPU cores
- At least 2 GB RAM

For GPU mining:

- Ubuntu 22.04 or newer
- Node.js 20+
- NVIDIA GPU
- NVIDIA driver installed
- CUDA toolkit installed
- `nvcc` available

## CPU Miner Installation

Use this for VPS or CPU-only mining.

```bash
cd /root
git clone https://github.com/404-Agent/codes-miner.git
cd /root/codes-miner

npm install
```

Build the native Rust CPU scanner:

```bash
cd /root/codes-miner/native-miner
cargo build --release
cd /root/codes-miner
```

Create the `.env` file:

```bash
cat > .env <<'ENV'
ETH_RPC=https://YOUR_ETH_MAINNET_RPC
MINER_PRIVATE_KEY=YOUR_MINER_PRIVATE_KEY
CODES_ADDRESS=0xdAeEB910888e3613638C6a9b71691C72B2e7DD36
CHAIN_ID=1
WORKERS=4
LOG_EVERY_MS=30000
NATIVE_REFRESH_MS=0
NATIVE_BIN=/root/codes-miner/native-miner/target/release/codes-native-miner
ENV
```

Run the CPU miner:

```bash
node mine-native.mjs
```

## CPU Miner With PM2

Start the CPU miner with PM2:

```bash
cd /root/codes-miner
pm2 start mine-native.mjs --name codes-cpu-miner
pm2 logs codes-cpu-miner
```

Restart the CPU miner:

```bash
pm2 restart codes-cpu-miner
```

Stop the CPU miner:

```bash
pm2 stop codes-cpu-miner
```

Save the PM2 process list:

```bash
pm2 save
```

## GPU Miner Installation

Use this for CUDA/NVIDIA GPU mining.

```bash
cd /root
git clone https://github.com/404-Agent/code-miner-gpu.git
cd /root/code-miner-gpu

npm install
```

Compile the CUDA miner for RTX 30xx GPUs:

```bash
cd /root/code-miner-gpu/gpu-miner
nvcc -O3 -arch=sm_86 codes-gpu-miner.cu -o codes-gpu-miner
cd /root/code-miner-gpu
```

Compile the CUDA miner for RTX 40xx GPUs:

```bash
cd /root/code-miner-gpu/gpu-miner
nvcc -O3 -arch=sm_89 codes-gpu-miner.cu -o codes-gpu-miner
cd /root/code-miner-gpu
```

Create the `.env` file:

```bash
cat > .env <<'ENV'
ETH_RPC=https://YOUR_ETH_MAINNET_RPC
MINER_PRIVATE_KEY=YOUR_MINER_PRIVATE_KEY
CODES_ADDRESS=0xdAeEB910888e3613638C6a9b71691C72B2e7DD36
CHAIN_ID=1
WORKERS=1
LOG_EVERY_MS=30000
NATIVE_REFRESH_MS=0
NATIVE_BIN=/root/code-miner-gpu/gpu-miner/codes-gpu-miner
ENV
```

Run the GPU miner:

```bash
node mine-gpu.mjs
```

## GPU Miner With PM2

Start the GPU miner with PM2:

```bash
cd /root/code-miner-gpu
pm2 start mine-gpu.mjs --name codes-gpu-miner
pm2 logs codes-gpu-miner
```

Restart the GPU miner:

```bash
pm2 restart codes-gpu-miner
```

Stop the GPU miner:

```bash
pm2 stop codes-gpu-miner
```

Save the PM2 process list:

```bash
pm2 save
```

## Miner Behavior

The miner should continuously:

1. Read the current mining batch.
2. Read the current challenge.
3. Scan nonces.
4. Find a valid hash below the current target.
5. Submit the valid nonce on-chain.
6. Wait for transaction confirmation.
7. Continue mining when the next batch is available.

If the mining wallet has already won the current batch, the miner should wait for the next batch.

## Log Monitoring

Check active miner processes:

```bash
ps aux | grep -E "mine-native|mine-gpu|codes" | grep -v grep
```

View CPU miner logs:

```bash
pm2 logs codes-cpu-miner
```

View GPU miner logs:

```bash
pm2 logs codes-gpu-miner
```

Check PM2 status:

```bash
pm2 status
```

## Troubleshooting

### Missing Node.js

Install Node.js 20:

```bash
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
node -v
npm -v
```

### Missing Rust

Install Rust:

```bash
curl https://sh.rustup.rs -sSf | sh
source "$HOME/.cargo/env"
rustc --version
cargo --version
```

### Missing CUDA Compiler

Check CUDA:

```bash
nvidia-smi
nvcc --version
```

If `nvcc` is missing, install the CUDA toolkit that matches the GPU driver.

### RPC Issues

If the miner cannot read the chain:

1. Check that `ETH_RPC` is a working Ethereum Mainnet RPC.
2. Avoid public RPCs with strict rate limits.
3. Use a dedicated RPC provider for stable mining.

### Wallet Already Won Current Batch

This is normal.

A wallet can win only once per batch. The miner should wait until the next batch.

### Transaction Reverted

Common reasons:

1. The nonce is no longer valid.
2. Another miner already submitted for the batch.
3. The wallet already won the current batch.
4. The wallet does not have enough ETH for gas.
5. The RPC returned stale data.

## Browser Mining

Browser mining is available from the $CODES website mining page.

Browser mining uses the connected wallet and requires wallet confirmation for submit transactions.

CLI, VPS, and GPU mining can auto-submit using `MINER_PRIVATE_KEY`.

## Dedicated Wallet Recommendation

Use a dedicated mining wallet.

Do not use a wallet that stores important funds or valuable assets.

The mining wallet should only contain enough ETH for mining transactions and gas.

## AI Agent Checklist

Before starting:

- [ ] Confirm the selected miner type: CPU or GPU
- [ ] Confirm Ethereum Mainnet RPC is available
- [ ] Confirm `CODES_ADDRESS` is correct
- [ ] Confirm `CHAIN_ID=1`
- [ ] Confirm `.env` exists
- [ ] Confirm private key is not printed in logs
- [ ] Confirm Node.js is installed
- [ ] Confirm Rust is installed for CPU mining
- [ ] Confirm CUDA is installed for GPU mining
- [ ] Start the miner
- [ ] Monitor logs
- [ ] Restart only if needed

## Public Website Link

When the website domain is active, this file can be linked as:

```txt
https://404agent.codes/skill.md
```

For local VPS testing, it can be served from:

```txt
http://5.39.217.232:3000/skill.md
```
