# EigenCompute CLI

Build decentralized compute services. Generate server implementations and smart contracts from Solidity interfaces, then deploy them to EigenCompute.

> ⚠️ **Alpha Software**: This CLI is in early development. APIs and generated code may change between versions.

## Quick Start

### 1. Install

```bash
npm install -g @eigenlayer/compute-cli
```

### 2. Create Your Project

```bash
compute init my-service
```

This creates a new project with:

- Template Solidity interface (`IMyServiceSpec.sol`)
- Foundry project structure
- Package.json with gen script

### 3. Define Your Interface

```bash
cd my-service
```

Edit the generated interface file to add your compute functions:

```solidity
// IMyServiceSpec.sol
interface IMyServiceSpec {
    function calculateSum(uint256 a, uint256 b) external returns (uint256);
    // Add your functions here
}
```

### 4. Generate Code

```bash
npm run gen
```

This generates:

- Complete server implementation (Rust)
- Smart contracts for EigenCompute
- Docker configuration
- Deployment scripts

### 5. Implement Your Logic

**Server logic** (e.g., `src/main.rs` for Rust):

```rust
// Find the generated function stub and add your implementation
async fn calculate_sum(a: U256, b: U256) -> Result<U256> {
    Ok(a + b)  // Your compute logic here
}
```

**Contract customization**:

- Modify `contracts/src/MyService.sol` for additional on-chain logic
- Add access controls, state variables, or events as needed

### 6. Deploy

```bash
export PRIVATE_KEY=0x123...
npm run deploy
```

Choose to deploy:

- **Offchain only**: Docker image to EigenDA
- **Onchain only**: Smart contract with forge
- **Both**: Complete deployment

That's it! Your decentralized compute service is ready.

---

## Interactive Mode

Run without arguments for a guided experience:

```bash
compute
```

## Commands

### `init` - Create New Project

```bash
compute init [project-name] [-l language] [-o directory]
```

### `gen` - Generate from Interface

```bash
compute gen [interface.sol] [-l language] [-o directory]
```

### `deploy` - Deploy Your Service

```bash
compute deploy [options]
```

## How It Works

1. **Users call** your deployed contract
2. **Operators execute** using your generated server
3. **Results return** to your contract with proofs
4. **Contract acts** on computed results

---

## Detailed Documentation

### Supported Languages

- **Rust** (`rust`, `rs`) - Fully supported
- **Python** (`python`, `py`) - Alpha support
- **TypeScript** (`typescript`, `ts`) - Coming soon
- **Go** (`golang`, `go`) - Coming soon

### Resource Constraints

You can modify the generated server code to build your application. However, there are some resource constraints you need to be aware of.
Currently we only support building for x86_64/amd64 architecture and only allow certain external calls

The following external calls are allowed. If you need access to them, read from these environment variables in your application:

- ETH_RPC_URL (Ethereum RPC URL)
- ARBITRUM_RPC_URL (Arbitrum RPC URL)
- BASE_RPC_URL (Base RPC URL)
- DA_PROXY_URL (EigenDA proxy URL)

### Project Structure

```
my-service/
├── src/                   # Server implementation
├── contracts/             # Smart contracts
├── Dockerfile             # Container config
└── package.json           # Project config
```

### Deployment Options

#### Networks

- `base-sepolia` (default) - EigenLayer testnet
- `localhost` - Local development
- Custom chains - Via chain ID and RPC URL

#### Deploy Command Options

```bash
compute deploy
  --network <network>          # Target network (default: base-sepolia)
  --dockerfile <path>          # Custom Dockerfile path
  --image <id>                 # Use existing Docker image
  --contract-path <path>       # Contract file location
  --private-key <key>          # Alternative to PRIVATE_KEY env var
  --offchain                   # Deploy only Docker image
  --onchain                    # Deploy only smart contract
  --all                        # Deploy both (same as no flag)
```

### Requirements

- **Node.js 16+**
- **For development**: Rust toolchain, Foundry
- **For deployment**: Docker, private key with funds

### Advanced Usage

#### Testing Locally

```bash
cd my-service
cargo run                    # Run server
docker build -t my-service . # Test with Docker
```

#### Contract Development

```bash
cd my-service/contracts
forge soldeer install        # Install dependencies
forge build                  # Compile
forge test                   # Run tests
```

#### Updating Your Deployment

```bash
cd my-service
npm run deploy:offchain      # Update server logic (keeps same contract)
npm run deploy:onchain       # Deploy new contract instance
npm run deploy               # Deploy both (new contract + server)
```

**Note**: Use `deploy:offchain` when you've only changed computation logic but kept the same interface. Your existing contract will automatically use the updated server code.

#### Using npx (No Installation)

```bash
npx @eigenlayer/compute-cli init
npx @eigenlayer/compute-cli gen interface.sol
npx @eigenlayer/compute-cli deploy
```

### Command Aliases

- `init` → `initialize`, `new`
- `gen` → `generate`, `create`

### Generated Files

**Server Code:**

- Complete async implementation
- Type definitions from Solidity
- Docker configuration

**Smart Contracts:**

- EigenCompute receiver contract
- Implementation contract
- Deployment scripts
- Foundry configuration

### Environment Variables

- `PRIVATE_KEY` - Required for deployment
- Custom RPC endpoints and contract addresses available via flags

## Examples

See `examples/` directory for sample projects.

## License

BUSL-1.1
