> ## Documentation Index
> Fetch the complete documentation index at: https://docs.genlabs.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Build your first contract

> Install the contract toolchain, compile an example contract with gen genie build, and understand the artifact manifest it produces.

This recipe gets you from zero to a compiled contract manifest. As an example, we use the **simple-token** solution from [from-token-to-amm](https://github.com/gen-bc/demos/tree/main/from-token-to-amm) (`solutions/02-simple-token`).

## Prerequisites

* The `gen` CLI on your `PATH`. See [Install the CLI](/reference/cli/install).

## Get the code

The example contract lives in [from-token-to-amm](https://github.com/gen-bc/demos/tree/main/from-token-to-amm) in the [demos](https://github.com/gen-bc/demos) repo. Clone it:

```bash theme={null}
git clone https://github.com/gen-bc/demos.git
cd demos/from-token-to-amm
```

From here, every command in this tutorial assumes you're in the `from-token-to-amm` workspace. The example we build is under [`solutions/02-simple-token/`](https://github.com/gen-bc/demos/tree/main/from-token-to-amm/solutions/02-simple-token).

[Genie](/reference/contracts/genie-sdk) is the Grid's Rust SDK for writing contracts; `gen genie` is its CLI, used here to install the build toolchain and compile crates to artifacts.

Before starting, make sure your machine has the contract toolchain (a recent rustc/cargo, the `riscv32im-unknown-none-elf` target, and the RISC-V linker and objcopy). Check and install it with:

```bash theme={null}
gen genie install-env --install
```

Run without `--install` to only report what's missing. Without the `riscv32im-unknown-none-elf` target in place, every `gen genie build` below fails.

## Step 1: Build one example contract

The example is a multi-component token contract: a `root` component (metadata and install gatekeeper), plus `issuer` and `holder` components you install after deploy.

Build it:

```bash theme={null}
gen genie build solutions/02-simple-token
```

`gen genie build` accepts a path to a contract crate directory (the folder that contains `Cargo.toml`).

## Step 2: Read what the build produced

The build writes into that crate's `artifacts/` directory. For this contract, the important output is:

```
solutions/02-simple-token/artifacts/
├── simple_token_modules.json      ← contract manifest
├── simple_token_0_root.o          ← root component binary
├── simple_token_0_root.abi.json
├── simple_token_1_issuer.o        ← issuer component binary
├── simple_token_1_issuer.abi.json
├── simple_token_2_holder.o        ← holder component binary
└── simple_token_2_holder.abi.json
```

The repo ships the manifest and ABI JSON files; the build step produces the `.o` binaries that were missing until now.

### The manifest (`*_modules.json`)

It lists every component in the contract and where to find its binary and ABI on disk:

```json theme={null}
{
  "schema_version": "1.0",
  "package_name": "demo-simple-token",
  "contract_name": "simple_token",
  "modules": [
    {
      "name": "root",
      "component_type_index": 0,
      "object_path": "simple_token_0_root.o",
      "abi_path": "simple_token_0_root.abi.json"
    },
    {
      "name": "issuer",
      "component_type_index": 1,
      "object_path": "simple_token_1_issuer.o",
      "abi_path": "simple_token_1_issuer.abi.json"
    },
    {
      "name": "holder",
      "component_type_index": 2,
      "object_path": "simple_token_2_holder.o",
      "abi_path": "simple_token_2_holder.abi.json"
    }
  ]
}
```

* **`contract_name`** — logical name of the contract; used in generated client code and logs.
* **`modules`** — one entry per component type this contract defines. Index `0` is always the root component created at deploy time.
* **`object_path` / `abi_path`** — paths relative to the manifest file to the compiled binary and ABI.

## What's next

* [Deploy a contract to DevNet](/tutorials/recipes/deploy-to-devnet) — push and deploy on DevNet with `gen client`.
