# How to Run `genlayer deploy` for Contract Deployment

> Learn how to run genlayer deploy for contract deployment. This guide explains the necessary RPC environment variables and contract file paths for deploying Python smart contracts to the GenLayer network.

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

---

**`genlayer deploy` executes the TypeScript script at [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts), which requires RPC environment variables and a correctly configured contract file path to deploy Python smart contracts to the GenLayer network.**

This guide walks through the complete configuration pipeline for the [`genlayerlabs/genlayer-project-boilerplate`](https://github.com/genlayerlabs/genlayer-project-boilerplate) repository. You'll learn how to set up network credentials, customize the deploy script, and execute contract deployments with the GenLayer CLI.

## Configure Network Credentials in `.env`

The deployment script relies on [`config/genlayer_config.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py) to load RPC connection details. This module builds 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. The project includes a `.env.example` you can copy as a starting template:

```dotenv

# .env — example for localnet deployment

RPCPROTOCOL=http
RPCHOST=127.0.0.1
RPCPORT=8545

```

The **dotenv** package automatically loads these values via `load_dotenv()`, requiring no additional code changes.

For developers switching between networks frequently, maintain separate environment files and swap them before deployment:

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

```

## Customize the Deploy Script

The [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts) file contains the core deployment logic. Understanding its structure lets you target different contracts and pass constructor arguments.

```ts
// deploy/deployScript.ts (excerpt)
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: [] });

```

**Key customization points:**

| Concern | Default Value | Modification Method |
|---------|-------------|---------------------|
| Contract file | [`contracts/football_bets.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/football_bets.py) | Edit the `filePath` constant or implement CLI argument parsing |
| Constructor arguments | `args: []` | Populate the array with your contract's `__init__` parameters |
| Retry attempts | `retries: 200` | Adjust based on network latency |

To deploy a different contract, update the path resolution:

```ts
// Deploy a custom contract
const filePath = path.resolve(process.cwd(), "contracts/my_contract.py");

```

To pass constructor arguments, modify the `deployContract` call:

```ts
const deployTransaction = await client.deployContract({
  code: contractCode,
  args: ["initial_value", 1000],  // Match your contract's __init__ signature
});

```

## Execute `genlayer deploy`

The project's [`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 the deployment from the repository root:

```bash
npm run deploy      # Uses the package.json script

# or invoke directly

genlayer deploy

```

The CLI performs three operations:

1. Initializes the GenLayer client with RPC settings from `.env`
2. Executes [`deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deployScript.ts), which reads and transmits the Python contract
3. Outputs the deployed contract address:

```

Contract deployed at address: 0xabc123…

```

## Verify Deployment Success

Confirm the deployment through either method:

- **CLI query**: Use GenLayer CLI commands to inspect the contract at the printed address
- **Frontend interface**: Check the `frontend/` directory for a web interface that connects to deployed contracts

## Troubleshooting Common Errors

| Error Message | Root Cause | Solution |
|---------------|-----------|----------|
| `Error: RPCPROTOCOL is not defined` | Missing environment variable | Verify `.env` contains all three required variables (`RPCPROTOCOL`, `RPCHOST`, `RPCPORT`) |
| Deployment hangs indefinitely | Unreachable RPC endpoint or stopped chain | Test connectivity with `curl $RPCHOST:$RPCPORT` and ensure the GenLayer node is running |
| Incorrect contract address | Script points to wrong file | Update `filePath` in [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts) to the intended contract |
| Constructor argument mismatch | Contract `__init__` expects parameters | Populate the `args` array in `client.deployContract()` with correct types and values |

## Full Example: Deploying a Token Contract

Assume you have [`contracts/my_token.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/my_token.py) requiring an `initialSupply` parameter.

**Step 1**: Ensure `.env` contains valid RPC settings.

**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: new Uint8Array(readFileSync(filePath)),
  args: [1000000],  // initialSupply as uint256
});

```

**Step 3**: Execute and verify:

```bash
npm run deploy

```

The terminal displays the contract address. Your token contract is now live on the configured network.

## Key Files Reference

| File | Purpose |
|------|---------|
| [`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) | Environment variable loader for RPC configuration |
| [`package.json`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/package.json) | Defines `npm run deploy` shortcut |
| [`contracts/football_bets.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/football_bets.py) | Default example contract |
| [`README.md`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/README.md) | Project documentation with deploy command reference |

## Summary

- **Network setup**: Define `RPCPROTOCOL`, `RPCHOST`, and `RPCPORT` in a `.env` file at the repository root
- **Script customization**: Point [`deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deployScript.ts) to your target contract file and supply constructor arguments in the `args` array
- **Execution**: Run `genlayer deploy` directly or via `npm run deploy`
- **Verification**: Confirm the printed contract address matches on-chain state

These steps enable reliable contract deployment across local, test, and mainnet environments in the GenLayer boilerplate.

## Frequently Asked Questions

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

`genlayer deploy` requires three environment variables: `RPCPROTOCOL` (http or https), `RPCHOST` (node IP or hostname), and `RPCPORT` (node port). These are read by [`config/genlayer_config.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/config/genlayer_config.py) and consumed by the deployment script to establish the GenLayer client connection.

### How do I deploy a contract other than the default football_bets.py?

Edit the `filePath` constant in [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts). Change `path.resolve(process.cwd(), "contracts/football_bets.py")` to point to your target contract file, such as [`contracts/my_contract.py`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/contracts/my_contract.py). The script reads this file as a `Uint8Array` and transmits it to the GenLayer network.

### Can I pass constructor arguments when using `genlayer deploy`?

Yes. Modify the `args` array in the `client.deployContract()` call within [`deploy/deployScript.ts`](https://github.com/genlayerlabs/genlayer-project-boilerplate/blob/main/deploy/deployScript.ts). Populate it with values matching your contract's `__init__` parameter signature. For example, `args: ["name", 1000]` passes a string and integer to the constructor.

### Why does my `genlayer deploy` command hang without output?

This typically indicates an unreachable RPC endpoint. Verify your `.env` values are correct and the GenLayer node is running. Test connectivity with `curl $RPCHOST:$RPCPORT`. Also check that no firewall rules block the connection to the specified port.