Skip to main content

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:


_10
flow init my-project

This creates:

  • flow.json - Project configuration
  • cadence/ directory structure
  • Example contracts, scripts, and tests
  • Emulator account setup

Options:


_10
# Configuration only (no project structure)
_10
flow init --config-only
_10
_10
# Global configuration
_10
flow init --global
_10
_10
# Custom service account
_10
flow 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
_11
flow generate contract MyToken
_11
_11
# Generate a new script
_11
flow generate script GetBalance
_11
_11
# Generate a new transaction
_11
flow generate transaction TransferTokens
_11
_11
# Generate a new test
_11
flow generate test MyToken

Generated Structure:


_10
cadence/
_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
_11
flow test
_11
_11
# Run specific test file
_11
flow test cadence/tests/MyToken.test.cdc
_11
_11
# Run with coverage
_11
flow test --coverage
_11
_11
# Run with verbose output
_11
flow test --verbose

📖 Learn more about testing

4. Deploy Contracts

Deploy your contracts with flow project deploy:


_11
# Deploy to emulator
_11
flow project deploy
_11
_11
# Deploy to testnet
_11
flow project deploy --network=testnet
_11
_11
# Deploy to mainnet
_11
flow project deploy --network=mainnet
_11
_11
# Update existing contracts
_11
flow 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
_10
flow config add account --name my-account --address 0x123 --private-key abc123
_10
_10
# Add a contract
_10
flow config add contract --name MyToken --filename ./cadence/contracts/MyToken.cdc
_10
_10
# Add a deployment
_10
flow config add deployment --network testnet --account my-account --contract MyToken

Remove Configuration Items


_10
# Remove an account
_10
flow config remove account my-account
_10
_10
# Remove a contract
_10
flow config remove contract MyToken
_10
_10
# Remove a deployment
_10
flow config remove deployment testnet my-account MyToken

📖 Learn more about configuration management

Account Management

Create Accounts


_10
# Interactive account creation
_10
flow accounts create
_10
_10
# Create with specific network
_10
flow accounts create --network testnet
_10
_10
# Create with custom key
_10
flow accounts create --key <private-key>

Manage Account Keys


_10
# Generate new key pair
_10
flow keys generate
_10
_10
# Decode a key
_10
flow keys decode <key>
_10
_10
# Derive public key from private key
_10
flow keys derive <private-key>

📖 Learn more about account management

Contract Interactions

Execute Scripts


_10
# Run a script
_10
flow scripts execute cadence/scripts/GetBalance.cdc
_10
_10
# Run with arguments
_10
flow scripts execute cadence/scripts/GetBalance.cdc --arg 0x123
_10
_10
# Run on specific network
_10
flow scripts execute cadence/scripts/GetBalance.cdc --network testnet

Send Transactions


_10
# Send a transaction
_10
flow transactions send cadence/transactions/TransferTokens.cdc
_10
_10
# Send with arguments
_10
flow transactions send cadence/transactions/TransferTokens.cdc --arg 0x123 --arg 100
_10
_10
# Send with specific signer
_10
flow transactions send cadence/transactions/TransferTokens.cdc --signer my-account

📖 Learn more about scripts and transactions

Dependency Management

Install Dependencies


_10
# Install a contract dependency
_10
flow dependencies install testnet://8a4dce54554b225d.NumberFormatter
_10
_10
# Install from mainnet
_10
flow dependencies install mainnet://f233dcee88fe0abe.FungibleToken
_10
_10
# Install with specific account
_10
flow dependencies install testnet://8a4dce54554b225d.NumberFormatter --account my-account

Manage Dependencies


_10
# Discover available contracts
_10
flow dependencies discover
_10
_10
# Install a contract dependency
_10
flow dependencies install testnet://8a4dce54554b225d.NumberFormatter

📖 Learn more about dependency management

Development Workflow

Local Development

  1. Start the emulator:

_10
flow emulator start

  1. Deploy contracts:

_10
flow project deploy

  1. Run tests:

_10
flow test

  1. Execute scripts:

_10
flow scripts execute cadence/scripts/GetBalance.cdc

  1. Send transactions:

_10
flow transactions send cadence/transactions/TransferTokens.cdc

Testnet Deployment

  1. Configure testnet account:

_10
flow config add account --name testnet-account --address 0x123 --private-key abc123

  1. Deploy to testnet:

_10
flow project deploy --network=testnet

  1. Test on testnet:

_10
flow scripts execute cadence/scripts/GetBalance.cdc --network=testnet

Import Schema

Use simplified imports in your Cadence code:


_10
// Instead of complex import paths
_10
import FungibleToken from 0x9a0766d93b6608b7
_10
_10
// Use simple contract names
_10
import "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
_10
flow 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
_11
flow emulator start
_11
_11
# 2. Deploy locally
_11
flow project deploy
_11
_11
# 3. Run tests
_11
flow test
_11
_11
# 4. Deploy to testnet
_11
flow project deploy --network=testnet

3. Use Descriptive Names

Choose clear names for accounts and contracts:


_10
# ✅ Good
_10
flow config add account --name testnet-deployer
_10
flow generate contract MyNFT
_10
_10
# ❌ Avoid
_10
flow config add account --name acc1
_10
flow generate contract c1

4. Secure Your Keys

Use secure key management:


_10
# Use file-based keys
_10
flow config add account --name my-account --key-file ./keys/my-account.key
_10
_10
# Use environment variables
_10
FLOW_PRIVATE_KEY=abc123 flow project deploy

📖 Learn more about security best practices