How to Run `genlayer deploy` for Contract Deployment
genlayer deploy executes the TypeScript script at 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 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 to load RPC connection details. This module builds a configuration dictionary from three required environment variables:
# 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:
# .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:
cp .env.testnet .env && genlayer deploy
Customize the Deploy Script
The deploy/deployScript.ts file contains the core deployment logic. Understanding its structure lets you target different contracts and pass constructor arguments.
// 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 |
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:
// Deploy a custom contract
const filePath = path.resolve(process.cwd(), "contracts/my_contract.py");
To pass constructor arguments, modify the deployContract call:
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 provides a convenience script:
// package.json
"scripts": {
"deploy": "genlayer deploy"
}
Run the deployment from the repository root:
npm run deploy # Uses the package.json script
# or invoke directly
genlayer deploy
The CLI performs three operations:
- Initializes the GenLayer client with RPC settings from
.env - Executes
deployScript.ts, which reads and transmits the Python contract - 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 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 requiring an initialSupply parameter.
Step 1: Ensure .env contains valid RPC settings.
Step 2: Modify deploy/deployScript.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:
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 |
Main deployment script executed by genlayer deploy |
config/genlayer_config.py |
Environment variable loader for RPC configuration |
package.json |
Defines npm run deploy shortcut |
contracts/football_bets.py |
Default example contract |
README.md |
Project documentation with deploy command reference |
Summary
- Network setup: Define
RPCPROTOCOL,RPCHOST, andRPCPORTin a.envfile at the repository root - Script customization: Point
deployScript.tsto your target contract file and supply constructor arguments in theargsarray - Execution: Run
genlayer deploydirectly or vianpm 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 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. Change path.resolve(process.cwd(), "contracts/football_bets.py") to point to your target contract file, such as 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. 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.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →