CLI Tools

Command Line Interface

Powerful CLI scripts to deploy contracts, interact with the blockchain, and manage your Flow applications. One-command deployment and interaction tools for faster development.

Contract Deployment
Deployment
Deploy smart contracts to Flow networks with a single command

deploy-nft.sh

Deploy NFT contract to testnet or mainnet

#!/bin/bash

# FlowDevKit NFT Deployment Script
# Usage: ./deploy-nft.sh [network] [contract-name]

set -e

NETWORK=${1:-testnet}
CONTRACT_NAME=${2:-FlowDevKitNFT}

echo "🚀 Deploying $CONTRACT_NAME to $NETWORK..."

# Check if Flow CLI is installed
if ! command -v flow &> /dev/null; then
    echo "❌ Flow CLI is not installed. Please install it first:"
    echo "   curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh | sh"
    exit 1
fi

# Check if flow.json exists
if [ ! -f "flow.json" ]; then
    echo "❌ flow.json not found. Initializing project..."
    flow init
fi

# Create contracts directory if it doesn't exist
mkdir -p contracts

# Download NFT contract template if it doesn't exist
if [ ! -f "contracts/$CONTRACT_NAME.cdc" ]; then
    echo "📥 Downloading NFT contract template..."
    curl -s https://raw.githubusercontent.com/flowdevkit/templates/main/contracts/NFT.cdc > "contracts/$CONTRACT_NAME.cdc"
fi

# Update flow.json with contract configuration
echo "⚙️  Configuring flow.json..."
cat > flow.json << EOF
{
  "contracts": {
    "$CONTRACT_NAME": "./contracts/$CONTRACT_NAME.cdc"
  },
  "networks": {
    "emulator": "127.0.0.1:3569",
    "testnet": "access.devnet.nodes.onflow.org:9000",
    "mainnet": "access.mainnet.nodes.onflow.org:9000"
  },
  "accounts": {
    "emulator-account": {
      "address": "f8d6e0586b0a20c7",
      "key": "2eae2f31cb5b756151fa11d82949c634b8f28796a711d7eb1e52cc301ed11111"
    }
  },
  "deployments": {
    "$NETWORK": {
      "emulator-account": ["$CONTRACT_NAME"]
    }
  }
}
EOF

# Deploy the contract
echo "📦 Deploying contract to $NETWORK..."
if [ "$NETWORK" = "emulator" ]; then
    # Start emulator if not running
    if ! pgrep -f "flow emulator" > /dev/null; then
        echo "🔧 Starting Flow emulator..."
        flow emulator start --verbose &
        sleep 5
    fi
fi

flow project deploy --network=$NETWORK

echo "✅ Successfully deployed $CONTRACT_NAME to $NETWORK!"
echo ""
echo "📋 Next steps:"
echo "   1. Verify deployment: flow accounts get <account-address> --network=$NETWORK"
echo "   2. Mint your first NFT: ./mint-nft.sh $NETWORK"
echo "   3. Set up collection: ./setup-collection.sh $NETWORK"
Usage Example
# Make script executable
chmod +x deploy-nft.sh

# Run with default parameters
./deploy-nft.sh

# Run with custom parameters
./deploy-nft.sh testnet MyContract 1000000
Common Issues
Permission denied: Run chmod +x script.sh
Flow CLI not found: Install from official docs
Network issues: Check your internet connection and network configuration
Contract Interaction
Interaction
Scripts to interact with deployed contracts - mint, transfer, query

mint-nft.sh

Mint NFTs from deployed contract

#!/bin/bash

# FlowDevKit NFT Minting Script
# Usage: ./mint-nft.sh [network] [recipient] [name] [description] [image-url]

set -e

NETWORK=${1:-testnet}
RECIPIENT=${2:-0x01}
NFT_NAME=${3:-"FlowDevKit NFT #1"}
DESCRIPTION=${4:-"A beautiful NFT created with FlowDevKit"}
IMAGE_URL=${5:-"https://flowdevkit.com/nft-placeholder.png"}

echo "🎨 Minting NFT: '$NFT_NAME' to $RECIPIENT on $NETWORK..."

# Create mint transaction if it doesn't exist
mkdir -p transactions

cat > transactions/mint_nft.cdc << EOF
import NonFungibleToken from 0x1d7e57aa55817448
import FlowDevKitNFT from 0x01
import MetadataViews from 0x1d7e57aa55817448

transaction(
    recipient: Address,
    name: String,
    description: String,
    thumbnail: String,
) {
    let minter: &FlowDevKitNFT.NFTMinter
    
    prepare(signer: AuthAccount) {
        self.minter = signer.borrow<&FlowDevKitNFT.NFTMinter>(from: FlowDevKitNFT.MinterStoragePath)
            ?? panic("Could not borrow a reference to the NFT minter")
    }
    
    execute {
        let recipient = getAccount(recipient)
        let receiver = recipient
            .getCapability(FlowDevKitNFT.CollectionPublicPath)
            .borrow<&{NonFungibleToken.CollectionPublic}>()
            ?? panic("Could not get receiver reference to the NFT Collection")
        
        let royalties: [MetadataViews.Royalty] = []
        
        self.minter.mintNFT(
            recipient: receiver,
            name: name,
            description: description,
            thumbnail: thumbnail,
            royalties: royalties
        )
    }
}
EOF

# Execute the minting transaction
echo "📦 Executing mint transaction..."
flow transactions send ./transactions/mint_nft.cdc \
    --arg Address:"$RECIPIENT" \
    --arg String:"$NFT_NAME" \
    --arg String:"$DESCRIPTION" \
    --arg String:"$IMAGE_URL" \
    --network=$NETWORK

echo "✅ Successfully minted NFT!"
echo ""
echo "🔍 Verify the mint:"
echo "   flow scripts execute ./scripts/get_nft_ids.cdc $RECIPIENT --network=$NETWORK"
Usage Example
# Make script executable
chmod +x mint-nft.sh

# Run with default parameters
./mint-nft.sh

# Run with custom parameters
./mint-nft.sh testnet MyContract 1000000
Common Issues
Permission denied: Run chmod +x script.sh
Flow CLI not found: Install from official docs
Network issues: Check your internet connection and network configuration
Query Scripts
Query
Read blockchain state - balances, NFT metadata, contract info

get-balance.cdc

Query token balance for an account

// Get Token Balance Script
import FungibleToken from 0xf233dcee88fe0abe
import FlowDevKitToken from 0x01

pub fun main(account: Address): UFix64 {
    let vaultRef = getAccount(account)
        .getCapability(FlowDevKitToken.VaultPublicPath)
        .borrow<&FlowDevKitToken.Vault{FungibleToken.Balance}>()
        ?? panic("Could not borrow Balance reference to the Vault")

    return vaultRef.balance
}
Usage Example
# Make script executable
chmod +x get-balance.cdc

# Run with default parameters
./get-balance.cdc

# Run with custom parameters
./get-balance.cdc testnet MyContract 1000000
Common Issues
Permission denied: Run chmod +x script.sh
Flow CLI not found: Install from official docs
Network issues: Check your internet connection and network configuration
Installation & Setup
Get started with FlowDevKit CLI tools in minutes

1. Install Flow CLI

# Install Flow CLI
curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh | sh

# Verify installation
flow version

2. Download FlowDevKit Scripts

# Clone FlowDevKit CLI tools
git clone https://github.com/flowdevkit/cli-tools.git
cd cli-tools

# Make scripts executable
chmod +x *.sh

3. Initialize Project

# Initialize new Flow project
flow init

# Or use FlowDevKit template
./init-project.sh my-flow-app

4. Deploy Your First Contract

# Deploy NFT contract to testnet
./deploy-nft.sh testnet MyNFT

# Deploy token contract
./deploy-token.sh testnet MyToken 1000000