# /deploy-smart-contract - Deploy Move Smart Contracts

**Agent:** `devops`

Deploy Move smart contracts to the Movement Network (testnet or mainnet).

**IMPORTANT**: Delegate to `devops` agent.

## Prerequisites

1. **Movement CLI installed** - See [Movement CLI docs](https://docs.movementnetwork.xyz/devs/movementcli)
2. **Wallet configured** with private key
3. **Sufficient tokens** from [faucet](https://faucet.movementnetwork.xyz/) (for testnet)

## Workflow

### Step 1: Verify Configuration

Check your `.movement/config.yaml` is configured for the target network:

#### Testnet Configuration
```yaml
---
profiles:
  default:
    network: Custom
    private_key: "0xYOUR_PRIVATE_KEY"
    public_key: "0xYOUR_PUBLIC_KEY"
    account: "YOUR_ACCOUNT_ADDRESS"
    rest_url: "https://full.testnet.movementinfra.xyz/v1"
    faucet_url: "https://faucet.testnet.movementnetwork.xyz/"
```

#### Mainnet Configuration
```yaml
---
profiles:
  default:
    network: Custom
    private_key: "0xYOUR_PRIVATE_KEY"
    public_key: "0xYOUR_PUBLIC_KEY"
    account: "YOUR_ACCOUNT_ADDRESS"
    rest_url: "https://full.mainnet.movementinfra.xyz/v1"
```

### Step 2: Configure Move.toml

Add your deployment address to `contracts/Move.toml`:

```toml
[addresses]
module_addr = "YOUR_ACCOUNT_ADDRESS"
```

Or use `_` for dynamic address assignment during deployment:
```toml
[addresses]
module_addr = "_"
```

### Step 3: Compile Contracts

```bash
cd contracts
movement move compile
```

Verify compilation succeeds without errors.

### Step 4: Run Tests

```bash
movement move test
```

Ensure all tests pass before deployment.

### Step 5: Deploy to Network

#### Testnet Deployment
```bash
cd contracts
movement move publish --named-addresses module_addr=default
```

#### Mainnet Deployment
```bash
cd contracts
movement move publish \
  --url https://full.mainnet.movementinfra.xyz/v1 \
  --named-addresses module_addr=default
```

### Step 6: Confirm Transaction

You'll be prompted:
```
Do you want to submit this transaction? [Y/n]
```

Type `Y` and press **Enter** to confirm.

> **Note:** Ensure you have sufficient tokens from the faucet before proceeding.

### Step 7: Verify Deployment

1. Note the transaction hash from the output
2. Verify on Movement Explorer:
   - Testnet: `https://explorer.movementnetwork.xyz/?network=testnet`
   - Mainnet: `https://explorer.movementnetwork.xyz/?network=mainnet`

### Step 8: Update Frontend Configuration

Update the contract address in `frontend/.env` so the frontend can interact with the deployed contract:

```bash
# frontend/.env
VITE_MODULE_ADDRESS=<YOUR_DEPLOYED_CONTRACT_ADDRESS>
VITE_NETWORK=testnet  # or mainnet
VITE_NODE_URL=https://full.testnet.movementinfra.xyz/v1  # or mainnet URL
```

Example:
```bash
VITE_MODULE_ADDRESS=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
VITE_NETWORK=testnet
VITE_NODE_URL=https://full.testnet.movementinfra.xyz/v1
```

> **Note:** After updating `.env`, restart the frontend dev server for changes to take effect.

## Sub-Commands

### /deploy-smart-contract:testnet
Deploy to testnet only.

### /deploy-smart-contract:mainnet
Deploy to mainnet (requires additional confirmation).

### /deploy-smart-contract:verify
Verify an existing deployment on the Explorer.

## Deployment Report

```markdown
# 📜 Smart Contract Deployment Complete!

## Network: {Testnet/Mainnet}
## Timestamp: {ISO timestamp}

## Deployed Modules
| Module | Address | Tx Hash |
|--------|---------|---------|
| {name} | 0x...   | 0x...   |

## Verification
- Explorer: {link}
- Status: ✅ Verified

## Next Steps
1. Test contract interactions from frontend
```

## Troubleshooting

### Insufficient Gas
Ensure you have enough MOVE tokens. Get testnet tokens from:
- Faucet: https://faucet.movementnetwork.xyz/

### Compilation Errors
Run `movement move compile` first and fix any errors.

### Account Not Found
Initialize your account:
```bash
movement init --network testnet
```

### Named Address Errors
Ensure `Move.toml` has the correct address mapping and use `--named-addresses` flag.

