# How to Configure `genlayer deploy` for Contract Deployment on GenLayer

> Learn how to configure genlayer deploy for contract deployment. Master RPC network setup and contract file paths with this essential guide.

- Repository: [GenLayer Labs/genlayer-project-boilerplate](https://github.com/genlayerlabs/genlayer-project-boilerplate)
- Tags: how-to-guide
- Published: 2026-08-20

---

**`genlayer deploy`** is the CLI command that executes the TypeScript deployment script in [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts), requiring proper RPC network configuration via environment variables and a correctly specified target contract file path.

The GenLayer project boilerplate provides a streamlined pipeline for deploying Python-based smart contracts. This guide walks through configuring `genlayer deploy` step-by-step, grounded in the actual source code of the repository.

---

## Configure Network Credentials via Environment Variables

The **RPC connection settings** are handled by [`config/genlayer_config.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py), which constructs a configuration dictionary from three required environment variables:

```python

# config/genlayer_config.py

def get_config() -> dict:
    config = {
        "rpc_protocol": os.environ["RPCPROTOCOL"],
        "rpc_host":     os.environ["RPCHOST"],
        "rpc_port":     os.environ["RPCPORT"],
    }
    return config

```

Create a `.env` file in the repository root (copy from `.env.example` if available):

```dotenv

# .env — example for localnet

RPCPROTOCOL=http
RPCHOST=127.0.0.1
RPCPORT=8545

```

The project uses **python-dotenv** to load these automatically. No code changes are required once the file is in place.

**Pro tip:** For multi-network workflows, maintain separate environment files and switch before deploying:

```bash
cp .env.testnet .env && genlayer deploy

```

---

## Verify and Customize the Deploy Script

The deployment logic lives in [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts). Key implementation details:

```ts
// deploy/deployScript.ts
const filePath = path.resolve(process.cwd(), "contracts/football_bets.py");
const contractCode = new Uint8Array(readFileSync(filePath));
await client.initializeConsensusSmartContract();
const deployTransaction = await client.deployContract({ code: contractCode, args: [] });

```

| Configuration Point | Default Value | How to Modify |
|---------------------|-------------|---------------|
| **Contract file path** | [`contracts/football_bets.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/football_bets.py) | Edit the `filePath` constant |
| **Constructor arguments** | `args: []` | Populate array with required params |
| **Retry attempts** | `retries: 200` | Adjust for network latency |

To deploy a different contract, update the path:

```ts
// deploy/deployScript.ts — modified for custom contract
const filePath = path.resolve(process.cwd(), "contracts/my_contract.py");

```

---

## Pass Constructor Arguments to genlayer deploy

If your contract's `__init__` method requires parameters, populate the `args` array with GenLayer-compatible values:

```ts
// Example: deploying a token with initial supply
const deployTransaction = await client.deployContract({
  code: contractCode,
  args: [1000],  // matches __init__(self, initial_supply)
});

```

Arguments must match the **order and types** expected by the Python contract's constructor.

---

## Execute the Deployment Command

The [`package.json`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/package.json) provides a convenience script:

```json
// package.json
"scripts": {
  "deploy": "genlayer deploy"
}

```

Run either:

```bash
npm run deploy        # recommended

# or directly:

genlayer deploy

```

The CLI will:

1. Initialize the GenLayer client with RPC settings from `.env`
2. Execute [`deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deployScript.ts) to read, compile, and submit the contract
3. Poll for confirmation and print the deployed address:

```

Contract deployed at address: 0xabc123...

```

---

## Troubleshooting Common `genlayer deploy` Errors

| Error Message | Root Cause | Resolution |
|-------------|-----------|------------|
| `Error: RPCPROTOCOL is not defined` | Missing environment variable | Verify `.env` contains all three RPC variables |
| Deployment hangs indefinitely | Chain unreachable or not running | Test connectivity: `curl $RPCHOST:$RPCPORT` |
| Wrong contract deployed | `filePath` points to incorrect file | Update path in [`deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deployScript.ts) |
| Transaction reverts | Missing or incorrect constructor args | Match `args` array to contract's `__init__` signature |

---

## Complete Configuration Example

Deploying [`contracts/my_token.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/my_token.py) with constructor arguments:

**Step 1:** Configure `.env`

```dotenv
RPCPROTOCOL=http
RPCHOST=127.0.0.1
RPCPORT=8545

```

**Step 2:** Modify [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts)

```ts
const filePath = path.resolve(process.cwd(), "contracts/my_token.py");
const deployTransaction = await client.deployContract({
  code: contractCode,
  args: [1000, "MyToken", "MTK"],  // supply, name, symbol
});

```

**Step 3:** Deploy

```bash
npm run deploy

```

---

## Key Source Files in the Boilerplate

| File | Purpose |
|------|---------|
| [[`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts)](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts) | Main deployment script executed by `genlayer deploy` |
| [[`config/genlayer_config.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py)](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py) | Environment-based RPC configuration loader |
| [[`package.json`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/package.json)](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/package.json) | npm script definitions including `"deploy"` |
| [[`contracts/football_bets.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/football_bets.py)](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/football_bets.py) | Reference contract used by default script |

---

## Summary

- **Network configuration** resides in `.env` with three required variables: `RPCPROTOCOL`, `RPCHOST`, `RPCPORT`
- **Contract selection** happens in [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts) via the `filePath` constant
- **Constructor arguments** pass through the `args` array in `client.deployContract()`
- **Execution** runs via `npm run deploy` or `genlayer deploy` directly
- **Verification** confirms the printed contract address matches on-chain deployment

---

## Frequently Asked Questions

### What environment variables does `genlayer deploy` require?

`genlayer deploy` requires **three environment variables** read by [`config/genlayer_config.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py): `RPCPROTOCOL` (e.g., `http`, `https`), `RPCHOST` (IP or domain), and `RPCPORT` (port number). These must be present in a `.env` file or exported in your shell before running the command.

### How do I deploy a different contract with `genlayer deploy`?

Edit [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts) and change the `filePath` constant to point to your target contract. The default value [`contracts/football_bets.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/football_bets.py) can be replaced with any Python contract file in your project, such as [`contracts/my_contract.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/my_contract.py).

### Can I pass arguments to my contract's constructor during deployment?

Yes. Populate the `args` array in the `client.deployContract()` call within [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts). The arguments must match the parameter order and types defined in your Python contract's `__init__` method.

### Why does `genlayer deploy` fail with "RPCPROTOCOL is not defined"?

This error indicates [`config/genlayer_config.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py) cannot find the required environment variable. Ensure your `.env` file exists in the repository root, contains `RPCPROTOCOL`, `RPCHOST`, and `RPCPORT`, and that `python-dotenv` loads it before the config function executes.