@krnl-dev/krnl-cli
v1.0.5
Published
Smart Contract deployment CLI specialized for KRNL use case
Readme
KRNL CLI
A specialized Smart Contract deployment CLI for KRNL use cases, built with modern Node.js and TypeScript.
Features
- 🚀 Init: Initialize new template projects with Foundry auto-installation
- 🔨 Compile: Compile smart contracts with auto-detection and progress tracking
- 📦 Deploy: Deploy contracts using Foundry scripts with network auto-detection
- ✅ Verify: Automatic contract verification on Etherscan with
--verifyflag - 🔐 Create-Attestor: Create custom attestors for verification
Installation
npm install -g @krnl-dev/krnl-cliOr use with npx:
npx @krnl-dev/krnl-cli init --name my-projectQuick Start
# Initialize a new project (auto-installs Foundry if needed)
krnl init --name my-project
cd my-project
# Compile smart contracts (auto-detects src/ or contracts/)
krnl compile
# Deploy to localhost (requires Anvil running)
krnl deploy --network localhost
# Deploy to Sepolia with verification
krnl deploy --network sepolia --verify
# Create a new attestor
krnl create-attestorCommands
Init
Initialize a new KRNL project from the Hello-KRNL template.
Features:
- Auto-installs Foundry (forge, cast, anvil) if not present or version < 1.0.0
- Clones Hello-KRNL template repository
- Installs npm dependencies
- Installs Foundry libraries (OpenZeppelin, Account Abstraction, forge-std)
- Creates
.envfrom.env.example
krnl init [options]Options:
-t, --template <template>: Template to use (default: "default")-n, --name <name>: Project name
Example:
krnl init --name my-krnl-project
cd my-krnl-projectCompile
Compile smart contracts with auto-detection of project structure.
Features:
- Auto-detects
src/orcontracts/directory - Auto-detects
out/orartifacts/output directory - Reads
foundry.tomlfor configuration - Zero-config compilation for standard Foundry projects
krnl compile [options]Options:
-c, --contracts <path>: Path to contracts directory (optional, auto-detected)-o, --output <path>: Output directory for artifacts (optional, auto-detected)-p, --project-dir <path>: Path to project root directory
Examples:
# Auto-detect everything
krnl compile
# Explicit paths
krnl compile -c ./src -o ./outDeploy
Deploy smart contracts using Foundry scripts with network auto-detection.
Features:
- Uses Foundry
forge scriptfor deployment - Auto-detects networks from
.envandfoundry.toml - Default script:
script/Deploy.s.sol - Auto-prefixes
PRIVATE_KEYwith0xif needed - Parses deployment address from script output
- Optional contract verification on block explorers
- Requires
ETHERSCAN_API_KEYin environment or.env - Supports
--verifywith--contract <Name>or--verify-all - Aligns compiler version for verification from
foundry.toml(solc), e.g. passes--compiler-version v0.8.23
- Requires
krnl deploy [options]Options:
-n, --network <network>: Network to deploy to (default: "localhost")--script <pathOrTarget>: Forge script file or target (default: "script/Deploy.s.sol")--verify: Verify contract on explorer (requires--contractor--verify-allwhen using--script)--contract <name>: Contract name to verify (required with--verifyand--script)--verify-all: Verify all contracts deployed by the script--constructor-args <args>: Constructor arguments for verification (if needed)
Examples:
# Deploy using default script to sepolia
krnl deploy --network sepolia
# Deploy with verification of a specific contract
krnl deploy --network sepolia --verify --contract RealEstateInvestment
# Deploy with verification of all contracts in script
krnl deploy --network sepolia --verify --verify-all
# Use custom script with specific contract target
krnl deploy --network sepolia --script "script/Deploy.s.sol:DeployRealEstateScript" --verify --verify-all
# Deploy to localhost (requires Anvil running)
krnl deploy --network localhostNetwork Detection:
- Reads
SEPOLIA_RPC_URL,MAINNET_RPC_URL, etc. from.env - Reads
[rpc_endpoints]fromfoundry.toml - Always includes
localhost(http://localhost:8545)
Verification Details:
- When using
--verifywith--script, you must specify either:--contract <Name>to verify a specific contract--verify-allto verify all contracts deployed by the script
- The CLI invokes
forge verify-contractwith:- Contract address (parsed from deployment output)
- Contract identifier:
src/<Contract>.sol:<Contract> --chain-id <id>--compiler-version v<solc>read fromfoundry.toml--etherscan-api-key <key>fromETHERSCAN_API_KEYenv var
- If
ETHERSCAN_API_KEYis missing and--verifyis enabled, the CLI will error with an actionable message
Environment Variables:
PRIVATE_KEY: Your wallet private key (required for deployment)ETHERSCAN_API_KEY: API key for contract verification (required with--verify)<NETWORK>_RPC_URL: RPC endpoint for the target network (e.g.,SEPOLIA_RPC_URL)- Additional env vars may be required by your deploy script (e.g.,
DELEGATED_ACCOUNT_ADDRESS)
Create-Attestor
Create custom attestors for contract verification.
krnl create-attestorRuns the create-attestor-standalone.sh script for Docker-based attestor creation.
Testing
The project includes a comprehensive smoke test script that validates the entire CLI workflow:
# Run smoke test on localhost (requires Anvil)
./scripts/smoke.sh
# Run smoke test on Sepolia testnet
NETWORK=sepolia \
SEPOLIA_RPC_URL="https://sepolia.infura.io/v3/YOUR_PROJECT_ID" \
PRIVATE_KEY="0x..." \
ETHERSCAN_API_KEY="YOUR_API_KEY" \
./scripts/smoke.sh
# Keep the generated project for inspection
KEEP_PROJECT=1 ./scripts/smoke.sh
# Skip build step (use existing dist/)
SKIP_BUILD=1 ./scripts/smoke.shThe smoke test performs:
krnl init- Creates a fresh projectkrnl compile- Compiles contractskrnl deploy- Deploys without verificationkrnl deploy --verify- Deploys with verification (if API key provided)- Cleanup - Removes project and stops Anvil
Development
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
# Run smoke test
./scripts/smoke.shArchitecture
- CLI Router: Commander.js-based command dispatcher
- UI Layer: Ink/InkUI components for interactive terminal experiences
- Configuration: YAML-based configuration management
- TypeScript: Full type safety throughout the codebase
- Error Handling: Comprehensive error reporting with actionable suggestions
Project Structure
src/
├── cli.ts # Main CLI entry point
├── commands/ # Individual command implementations
│ ├── init/ # Project initialization with Foundry setup
│ │ ├── index.tsx # Init command UI
│ │ └── ui.tsx # Init progress components
│ ├── compile/ # Smart contract compilation
│ │ ├── index.tsx # Compile command UI
│ │ └── ui.tsx # Compile progress components
│ ├── deploy/ # Deployment via Foundry scripts
│ │ ├── index.tsx # Deploy command UI
│ │ └── ui.tsx # Deploy progress components
│ └── create-attestor/ # Attestor creation
│ └── index.tsx
├── components/ # Shared UI components
│ ├── Spinner.tsx
│ └── Message.tsx
├── utils/ # Utility functions
│ ├── config.ts # Configuration management
│ ├── branding.ts # KRNL logo and branded styles
│ ├── foundry.ts # Foundry integration utilities
│ └── networks.ts # Network detection and RPC management
└── scripts/ # Development and testing scripts
└── smoke.sh # End-to-end smoke testRequirements
- Node.js: v18 or higher
- Foundry: Auto-installed by
krnl initif not present- forge
- cast
- anvil
- Git: Required for cloning templates
Troubleshooting
Foundry not found
If you see "Foundry not found" errors, run:
curl -L https://foundry.paradigm.xyz | bash
foundryupVerification fails
- Ensure
ETHERSCAN_API_KEYis set in your environment or.env - When using
--verifywith--script, you must specify:--contract <Name>for a specific contract, OR--verify-allto verify all contracts
- Check that your contract source matches the deployed bytecode
Network not detected
- Add RPC URL to
.env:SEPOLIA_RPC_URL=https://... - Or add to
foundry.toml:[rpc_endpoints] sepolia = "https://..."
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run smoke tests:
./scripts/smoke.sh - Submit a pull request
License
ISC
