> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Ge0frey/nullgraph/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> Step-by-step installation and configuration of NullGraph

This guide walks you through building, deploying, and running NullGraph locally.

## Installation

<Steps>
  ### Clone the Repository

  Clone the NullGraph repository and navigate to the project directory:

  ```bash theme={null}
  git clone <repository-url>
  cd nullgraph
  ```

  ### Install Root Dependencies

  Install the root-level dependencies for Anchor testing and scripts:

  ```bash theme={null}
  npm install
  ```

  This installs:

  * `@coral-xyz/anchor` (v0.31.1) - Anchor framework for Solana
  * `@solana/spl-token` (v0.4.14) - SPL Token utilities
  * Testing dependencies (Mocha, Chai, TypeScript)

  ### Install Frontend Dependencies

  Navigate to the frontend directory and install dependencies:

  ```bash theme={null}
  cd app
  npm install
  cd ..
  ```

  The frontend uses:

  * React 19.2 with TypeScript 5.9
  * Vite 7.3 for build tooling
  * Tailwind CSS 4.2 for styling
  * Solana wallet adapter libraries
  * React Router 7.13 for routing

  ### Configure Solana CLI

  Set your Solana CLI to point to devnet:

  ```bash theme={null}
  solana config set --url devnet
  ```

  Verify the configuration:

  ```bash theme={null}
  solana config get
  ```

  You should see:

  ```
  RPC URL: https://api.devnet.solana.com
  ```
</Steps>

## Build and Deploy

<Steps>
  ### Build the Anchor Program

  Compile the Solana program:

  ```bash theme={null}
  anchor build
  ```

  This compiles the Rust program in `programs/nullgraph/src/lib.rs` and generates:

  * Program binary in `target/deploy/nullgraph.so`
  * IDL in `target/idl/nullgraph.json`
  * TypeScript types in `target/types/nullgraph.ts`

  <Note>
    The build process may take several minutes on the first run as it downloads and compiles dependencies.
  </Note>

  ### Deploy to Devnet

  Deploy the compiled program to Solana devnet:

  ```bash theme={null}
  anchor deploy --provider.cluster devnet
  ```

  This uploads the program to devnet and returns a program ID. The default program ID is:

  ```
  2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK
  ```

  <Warning>
    Deployment requires SOL for transaction fees and rent. Ensure your wallet has at least 2 SOL. Use `solana airdrop 2 --url devnet` to get devnet SOL.
  </Warning>

  ### Initialize the Protocol

  Run the one-time initialization script to create the protocol state account:

  ```bash theme={null}
  npx ts-node scripts/init-protocol.ts
  ```

  This script:

  1. Derives the `ProtocolState` PDA from seed `["protocol_state"]`
  2. Calls `initialize_protocol` with fee set to 250 basis points (2.5%)
  3. Sets your wallet as the protocol authority and treasury
  4. Initializes NKA and bounty counters to zero

  Expected output:

  ```
  Authority: <your-public-key>
  Protocol State PDA: <protocol-state-address>
  Treasury (same as authority): <your-public-key>
  Initializing protocol with fee_basis_points = 250 (2.5%)...
  Transaction signature: <signature>
  Protocol initialized successfully!
  ```

  <Note>
    If the protocol is already initialized, the script will detect the existing account and skip initialization.
  </Note>
</Steps>

## Run the Frontend

<Steps>
  ### Start the Development Server

  Navigate to the app directory and start Vite:

  ```bash theme={null}
  cd app
  npm run dev
  ```

  The development server starts at:

  ```
  http://localhost:5173
  ```

  ### Connect Your Wallet

  1. Open `http://localhost:5173` in your browser
  2. Click "Connect Wallet" in the navigation bar
  3. Select Phantom from the wallet list
  4. Approve the connection in the Phantom popup
  5. Ensure Phantom is set to **Devnet**

  <Warning>
    If you see wallet connection errors, verify that:

    * Phantom is installed and unlocked
    * Phantom is set to Devnet network
    * You're using a supported browser (Chrome, Firefox, Brave, Edge)
  </Warning>
</Steps>

## Configuration

### Environment Variables

The frontend accepts optional environment variables. Create `app/.env` if you need custom configuration:

```bash theme={null}
# Optional: Custom RPC endpoint
VITE_RPC_URL=https://api.devnet.solana.com

# Optional: Custom program ID (if you deployed your own)
VITE_PROGRAM_ID=2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK
```

### Update IDL After Program Changes

If you modify the Anchor program, rebuild and sync the IDL to the frontend:

```bash theme={null}
# Rebuild the program
anchor build

# Copy IDL and types to frontend
cp target/idl/nullgraph.json app/src/lib/nullgraph.json
cp target/types/nullgraph.ts app/src/lib/nullgraph_types.ts
```

## Testing

### Run Anchor Tests

Test the program using the Anchor test suite:

```bash theme={null}
# Run against local validator (auto-starts/stops)
anchor test

# Run against existing devnet deployment
anchor test --skip-local-validator --provider.cluster devnet
```

The test suite (`tests/nullgraph.ts`) covers:

* Protocol initialization
* NKA submission and counter increment
* Bounty creation with BIO escrow
* Bounty submissions and approvals
* Fee calculation and distribution
* Error cases (invalid status, duplicate init, etc.)

## Architecture Overview

NullGraph runs entirely on Solana with no backend server:

```
React Frontend (Vite)
       |
       v
  Wallet Adapter
       |
       v
 Solana Devnet RPC
       |
       v
NullGraph Program (Anchor)
  - ProtocolState PDA
  - NullResult PDAs (NKAs)
  - NullBounty PDAs
  - BountySubmission PDAs
  - Vault Token Accounts
```

**Key Components:**

* **Program ID:** `2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK`
* **BIO Token Mint:** `GkjGV1ZF5BsMs6oAvk8jZiuXM8KwuygFCHLBpqR5Q14j`
* **RPC Endpoint:** `https://api.devnet.solana.com`
* **Network:** Solana Devnet

## Troubleshooting

### Build Errors

**Error:** `anchor: command not found`

**Solution:** Ensure Anchor CLI is installed and in your PATH:

```bash theme={null}
anchor --version
```

**Error:** `failed to get recent blockhash: FetchError`

**Solution:** Check your internet connection and verify Solana CLI config:

```bash theme={null}
solana config get
```

### Deployment Errors

**Error:** `Insufficient SOL balance`

**Solution:** Airdrop devnet SOL:

```bash theme={null}
solana airdrop 2 --url devnet
```

**Error:** `Transaction simulation failed`

**Solution:** The program may already be deployed. Check the program account:

```bash theme={null}
solana program show 2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK --url devnet
```

### Frontend Errors

**Error:** `Failed to connect to wallet`

**Solution:** Ensure Phantom is installed, unlocked, and set to Devnet.

**Error:** `Program account does not exist`

**Solution:** Deploy the program or use the existing devnet deployment.

## Next Steps

Now that NullGraph is running, proceed to the [Quickstart Guide](/getting-started/quickstart) to submit your first NKA and create a bounty.
