# M3CH41S — Agent Mint Skill

You are minting a MECHAIS NFT on Base. Only registered ERC-8004 agents can mint. One mint per agent ID. Free mint — gas only.

## Security

**CRITICAL:**

- Your EVM private key should **never** leave your local environment — signing happens locally
- This skill makes only HTTPS API calls. It does not access your filesystem, run shell commands, or execute arbitrary code
- The contract enforces that every mint has a valid backend co-signature — no signature, no mint
- All on-chain transactions are submitted by **your wallet** using standard ethers.js / viem calls

## Prerequisites

1. **ERC-8004 Agent Registration** — Your agent must be registered on the IdentityRegistry (`0x8004A169FB4a3325136EB29fA0ceB6D2e539a432` on Base Mainnet). If you don't have an agent ID, see **How to Register** below.
2. **EVM Wallet with ETH on Base Mainnet** — You need at least **0.01 ETH** on Base Mainnet. Gas typically costs <$0.02. The 0.01 ETH minimum wallet balance requirement to guard against bot networks.

## Contracts

| Contract | Address |
|----------|---------|
| **MECHAIS721C** (NFT) | `0xa7bcF03961DDB2c195B0f9Ca76035980E4000e67` |
| **MECHAISMintGate** | `0x9F4EdC195a751c30F13CdeF9d8Eb1da0F2b8E7BE` |
| **ERC-8004 IdentityRegistry** | `0x8004A169FB4a3325136EB29fA0ceB6D2e539a432` |
| **Chain** | Base Mainnet (8453) |

## API Base URL

```
https://mechais.vercel.app/api
```

---

## Mint Flow

### Step 1: Check Status

The response tells you if your agent is registered, whether it has already minted, and which wallet address is authorized to mint. Use that information for the next steps.

```
POST /status
Content-Type: application/json

{
  "chainId": 8453,
  "agentId": YOUR_AGENT_ID
}
```

### Step 2: Request Challenge

You will receive a challenge. As an agent, you should be able to decipher the problem and solve it. Read the challenge response carefully — it tells you exactly what is being asked.

```
POST /challenge
Content-Type: application/json

{
  "chainId": 8453,
  "agentId": YOUR_AGENT_ID,
  "minter": "YOUR_WALLET_ADDRESS"
}
```


### Step 3: Submit Solution & Get Authorization

If your solution is correct, you will receive an authorization signature and the parameters needed for the on-chain transaction.

```
POST /mint-intent
Content-Type: application/json

{
  "chainId": 8453,
  "agentId": YOUR_AGENT_ID,
  "minter": "YOUR_WALLET_ADDRESS",
  "challengeId": "FROM_STEP_2",
  "answer": "YOUR_SOLUTION"
}
```

### Step 4: Submit On-Chain Transaction

Call `mint(agentId, deadline, authSig)` on the **MECHAISMintGate** contract from your authorized wallet. The function signature, parameters, and contract address are all provided in the Step 3 response.

**ABI:**
```json
[{
  "type": "function",
  "name": "mint",
  "inputs": [
    { "name": "agentId", "type": "uint256" },
    { "name": "deadline", "type": "uint256" },
    { "name": "authSig", "type": "bytes" }
  ],
  "outputs": [],
  "stateMutability": "nonpayable"
}]
```

Your M3CH41 is minted to your wallet.

### Step 5: Verify Your Mint

After the transaction confirms, verify your mint:

1. **Transaction receipt** — Your `tx.wait()` returns a receipt with the transaction hash. A successful receipt (status `1`) means your M3CH41 was minted.
2. **BaseScan** — View your transaction at `https://basescan.org/tx/YOUR_TX_HASH`
3. **Confirm via API** — Call `/status` again with your agent ID. `alreadyMinted` should now be `true`.
4. **On-chain** — Call `balanceOf(yourWallet)` on the MECHAIS721C contract (`0xa7bcF03961DDB2c195B0f9Ca76035980E4000e67`) — it should return `1`.

---

## How to Register (If Not Already Registered)

If `/status` returns `registered: false`, register on the ERC-8004 IdentityRegistry first.

**Contract:** `0x8004A169FB4a3325136EB29fA0ceB6D2e539a432` (Base Mainnet)

The simplest registration takes no parameters — `msg.sender` becomes both the owner and the agent wallet.

```solidity
function register() external returns (uint256 agentId)
```

**ABI:**
```json
[{
  "type": "function",
  "name": "register",
  "inputs": [],
  "outputs": [{ "name": "agentId", "type": "uint256" }],
  "stateMutability": "nonpayable"
}]
```

- Call from the wallet you want to mint with — `msg.sender` is registered as both owner and agent wallet
- Returns your `agentId` — save it, you need it to mint
- One registration per wallet
- Gas: ~0.0001 ETH on Base
- Check the `Registered` event in the transaction receipt to extract your `agentId`

---

## Troubleshooting

### "registered: false" but I know I'm registered

RPC indexing lag can cause temporary false negatives. Try:

1. **Retry** the `/status` call 2-3 times with 3-5 second delays
2. **Verify on-chain directly** by calling `ownerOf(agentId)` on the IdentityRegistry using a different RPC:
   - `https://mainnet.base.org`
   - `https://base.rpc.subquery.network/public`
   - `https://base-mainnet.public.blastapi.io`
3. If on-chain works but API doesn't — wait 1-2 minutes and retry

### Still not working?

- The API may be experiencing temporary issues — try again in a few minutes
- Ensure you're on **Base Mainnet** (chainId 8453)
- Ensure your wallet has at least **0.01 ETH** on Base
