Commands Overview
Flow CLI provides a set of powerful commands that simplify your development workflow. These "super commands" handle complex tasks automatically, letting you focus on writing your smart contracts while the CLI manages the rest.
Project Lifecycle
1. Initialize a Project
Start a new Flow project with flow init
:
_10flow init my-project
This creates:
flow.json
- Project configurationcadence/
directory structure- Example contracts, scripts, and tests
- Emulator account setup
Options:
_10# Configuration only (no project structure)_10flow init --config-only_10_10# Global configuration_10flow init --global_10_10# Custom service account_10flow init --service-private-key <key>
📖 Learn more about project initialization
2. Generate Project Files
Create new files with the flow generate
command:
_11# Generate a new contract_11flow generate contract MyToken_11_11# Generate a new script_11flow generate script GetBalance_11_11# Generate a new transaction_11flow generate transaction TransferTokens_11_11# Generate a new test_11flow generate test MyToken
Generated Structure:
_10cadence/_10├── contracts/_10│ └── MyToken.cdc_10├── scripts/_10│ └── GetBalance.cdc_10├── transactions/_10│ └── TransferTokens.cdc_10└── tests/_10 └── MyToken.test.cdc
3. Run Tests
Test your contracts with flow test
:
_11# Run all tests_11flow test_11_11# Run specific test file_11flow test cadence/tests/MyToken.test.cdc_11_11# Run with coverage_11flow test --coverage_11_11# Run with verbose output_11flow test --verbose
4. Deploy Contracts
Deploy your contracts with flow project deploy
:
_11# Deploy to emulator_11flow project deploy_11_11# Deploy to testnet_11flow project deploy --network=testnet_11_11# Deploy to mainnet_11flow project deploy --network=mainnet_11_11# Update existing contracts_11flow project deploy --update
📖 Learn more about project deployment
Configuration Management
Add Configuration Items
Use flow config add
to manage your project configuration:
_10# Add an account_10flow config add account --name my-account --address 0x123 --private-key abc123_10_10# Add a contract_10flow config add contract --name MyToken --filename ./cadence/contracts/MyToken.cdc_10_10# Add a deployment_10flow config add deployment --network testnet --account my-account --contract MyToken
Remove Configuration Items
_10# Remove an account_10flow config remove account my-account_10_10# Remove a contract_10flow config remove contract MyToken_10_10# Remove a deployment_10flow config remove deployment testnet my-account MyToken
📖 Learn more about configuration management
Account Management
Create Accounts
_10# Interactive account creation_10flow accounts create_10_10# Create with specific network_10flow accounts create --network testnet_10_10# Create with custom key_10flow accounts create --key <private-key>
Manage Account Keys
_10# Generate new key pair_10flow keys generate_10_10# Decode a key_10flow keys decode <key>_10_10# Derive public key from private key_10flow keys derive <private-key>
📖 Learn more about account management
Contract Interactions
Execute Scripts
_10# Run a script_10flow scripts execute cadence/scripts/GetBalance.cdc_10_10# Run with arguments_10flow scripts execute cadence/scripts/GetBalance.cdc --arg 0x123_10_10# Run on specific network_10flow scripts execute cadence/scripts/GetBalance.cdc --network testnet
Send Transactions
_10# Send a transaction_10flow transactions send cadence/transactions/TransferTokens.cdc_10_10# Send with arguments_10flow transactions send cadence/transactions/TransferTokens.cdc --arg 0x123 --arg 100_10_10# Send with specific signer_10flow transactions send cadence/transactions/TransferTokens.cdc --signer my-account
📖 Learn more about scripts and transactions
Dependency Management
Install Dependencies
_10# Install a contract dependency_10flow dependencies install testnet://8a4dce54554b225d.NumberFormatter_10_10# Install from mainnet_10flow dependencies install mainnet://f233dcee88fe0abe.FungibleToken_10_10# Install with specific account_10flow dependencies install testnet://8a4dce54554b225d.NumberFormatter --account my-account
Manage Dependencies
_10# Discover available contracts_10flow dependencies discover_10_10# Install a contract dependency_10flow dependencies install testnet://8a4dce54554b225d.NumberFormatter
📖 Learn more about dependency management
Development Workflow
Local Development
- Start the emulator:
_10flow emulator start
- Deploy contracts:
_10flow project deploy
- Run tests:
_10flow test
- Execute scripts:
_10flow scripts execute cadence/scripts/GetBalance.cdc
- Send transactions:
_10flow transactions send cadence/transactions/TransferTokens.cdc
Testnet Deployment
- Configure testnet account:
_10flow config add account --name testnet-account --address 0x123 --private-key abc123
- Deploy to testnet:
_10flow project deploy --network=testnet
- Test on testnet:
_10flow scripts execute cadence/scripts/GetBalance.cdc --network=testnet
Import Schema
Use simplified imports in your Cadence code:
_10// Instead of complex import paths_10import FungibleToken from 0x9a0766d93b6608b7_10_10// Use simple contract names_10import "FungibleToken"
The CLI automatically resolves imports based on your flow.json
configuration.
Best Practices
1. Use Configuration Commands
Instead of manually editing flow.json
, use CLI commands:
_10# ✅ Good_10flow config add account --name my-account --address 0x123_10_10# ❌ Avoid_10# Manually editing flow.json
2. Test Locally First
Always test on emulator before deploying:
_11# 1. Start emulator_11flow emulator start_11_11# 2. Deploy locally_11flow project deploy_11_11# 3. Run tests_11flow test_11_11# 4. Deploy to testnet_11flow project deploy --network=testnet
3. Use Descriptive Names
Choose clear names for accounts and contracts:
_10# ✅ Good_10flow config add account --name testnet-deployer_10flow generate contract MyNFT_10_10# ❌ Avoid_10flow config add account --name acc1_10flow generate contract c1
4. Secure Your Keys
Use secure key management:
_10# Use file-based keys_10flow config add account --name my-account --key-file ./keys/my-account.key_10_10# Use environment variables_10FLOW_PRIVATE_KEY=abc123 flow project deploy
📖 Learn more about security best practices
Related Documentation
- Configuration Management - Learn how to manage your
flow.json
file - Project Deployment - Deploy contracts to different networks
- Account Management - Create and manage Flow accounts
- Testing - Write and run tests for your contracts
- Security - Secure your private keys and configuration