### Start Flow Emulator Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Starts the Flow Emulator. This is a prerequisite for deploying your project to the emulator network. ```shell flow emulator --start ``` -------------------------------- ### Progress Indicator Example Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Visual feedback for longer running commands is crucial to prevent user confusion. This example shows a loading indicator. ```text Loading 0x1fd892083b3e2a4c...⠼ ``` -------------------------------- ### Install Dependencies with Go Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Use this command to fetch all necessary dependencies for the Go project. ```bash go get ./... ``` -------------------------------- ### Help Screen Structure Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md The main help screen should list all commands with descriptions and examples. It should be displayed when a command is run without arguments. The structure includes Description, Usage, Examples, Commands, and Flags sections. ```text Description: Usage: Examples: An optional section of example(s) on how to run the command. Commands: … Flags: -- -- … ``` -------------------------------- ### Test File Structure Example Source: https://context7.com/onflow/flow-cli/llms.txt An example of a Cadence test file using the testing framework. It includes contract deployment, transaction execution, and assertions. ```cadence import Test import "HelloWorld" access(all) let account = Test.createAccount() access(all) fun setup() { let err = Test.deployContract( name: "HelloWorld", path: "../contracts/HelloWorld.cdc", arguments: [] ) Test.expect(err, Test.beNil()) } access(all) fun testGreeting() { let greeting = HelloWorld.hello() Test.assertEqual("Hello, World!", greeting) } access(all) fun testUpdateGreeting() { let txResult = Test.executeTransaction( "../transactions/UpdateGreeting.cdc", ["New Greeting"], [account] ) Test.expect(txResult, Test.beSucceeded()) let greeting = HelloWorld.hello() Test.assertEqual("New Greeting", greeting) } ``` -------------------------------- ### Start Flow Emulator Source: https://context7.com/onflow/flow-cli/llms.txt The `flow emulator` command starts a local Flow blockchain emulator. Options include verbose logging, specifying a port, enabling the REST API, and persisting emulator state. ```bash flow emulator ``` ```bash flow emulator --verbose ``` ```bash flow emulator --port 3569 ``` ```bash flow emulator --rest-port 8888 ``` ```bash flow emulator --persist ``` ```text # INFO[0000] Starting emulator on port 3569 # INFO[0000] Service Account: 0xf8d6e0586b0a20c7 # INFO[0000] Private Key: ... ``` -------------------------------- ### Install Project Dependencies Source: https://context7.com/onflow/flow-cli/llms.txt Install all external contract dependencies defined in your `flow.json` file. This command ensures local development environments have the correct contract versions. ```bash flow dependencies install ``` -------------------------------- ### Example flow.json Dependencies Configuration Source: https://context7.com/onflow/flow-cli/llms.txt This JSON structure illustrates how to configure external contract dependencies, including their source, hash, and network-specific aliases. ```json { "dependencies": { "FlowToken": { "source": "mainnet://1654653399040a61.FlowToken", "hash": "abc123...", "aliases": { "testnet": "0x7e60df042a9c0868", "mainnet": "0x1654653399040a61", "emulator": "0xf8d6e0586b0a20c7" } }, "NonFungibleToken": { "source": "mainnet://1d7e57aa55817448.NonFungibleToken", "hash": "def456...", "aliases": { "testnet": "0x631e88ae7f1d7c20", "mainnet": "0x1d7e57aa55817448", "emulator": "0xf8d6e0586b0a20c7" } } } } ``` -------------------------------- ### Flow CLI Command: Get Accounts with Filter Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Example of using a flag with a value in the Flow CLI. Supports space-delimited or equals-sign delimited values. ```bash flow accounts get --filter "address" ``` -------------------------------- ### Flow CLI Command: Accounts Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Example of a Flow CLI command for managing accounts. This demonstrates the 'noun verb' pattern for subcommands. ```bash flow accounts ``` -------------------------------- ### Add Core Contracts Interactively Source: https://context7.com/onflow/flow-cli/llms.txt Add core Flow contracts to your project dependencies interactively. The CLI will guide you through the process. ```bash flow dependencies add ``` -------------------------------- ### Flow CLI Command: Get Accounts with Argument Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Example of using a positional argument in the Flow CLI. Arguments are used for required values when flags are not preferred. ```bash flow accounts get
``` -------------------------------- ### Generate Transaction Template Source: https://context7.com/onflow/flow-cli/llms.txt Creates a boilerplate template for a Cadence transaction. This provides a starting point for defining transaction logic. ```bash flow generate transaction TransferTokens ``` -------------------------------- ### Generate New Contract with Flow CLI Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Run this command to create a new Cadence contract file and automatically add it to your project's flow.json configuration. This is the starting point for new smart contracts. ```shell flow generate contract ``` -------------------------------- ### Get Account Information on Testnet Source: https://context7.com/onflow/flow-cli/llms.txt Retrieve account information for a given address on the testnet network. Use the --network flag to specify the target network. ```bash flow accounts get 0x123 --network testnet ``` -------------------------------- ### Add External Contract Dependency Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Use this command to install external contract dependencies like NonFungibleToken. Ensure you verify the authenticity of third-party contracts. ```shell flow deps add mainnet://1d7e57aa55817448.NonFungibleToken ``` -------------------------------- ### Get Block with Transactions Included Source: https://context7.com/onflow/flow-cli/llms.txt Fetches a block's details along with all transactions included in that block. ```bash flow blocks get latest --include transactions ``` -------------------------------- ### Get Account Information on Mainnet Source: https://context7.com/onflow/flow-cli/llms.txt Retrieve account information for a given address on the mainnet network. Ensure you specify the correct network using the --network flag. ```bash flow accounts get 0x123 --network mainnet ``` -------------------------------- ### Get Block by Height Source: https://context7.com/onflow/flow-cli/llms.txt Fetches block details for a specific block height. Replace `12345` with the desired block number. ```bash flow blocks get 12345 ``` -------------------------------- ### Get Account Information from Emulator Source: https://context7.com/onflow/flow-cli/llms.txt Fetch account details from a local Flow emulator instance. The default network for emulator is often used unless specified otherwise. ```bash flow accounts get 0x123 --network emulator ``` -------------------------------- ### Get Current Node Version Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the current version boundary information for the node. Requires the NodeVersionBeacon contract. ```cadence import NodeVersionBeacon from 0xe467b9dd11fa00df access(all) fun main(): NodeVersionBeacon.Semver { return NodeVersionBeacon.getCurrentVersionBoundary().version } ``` -------------------------------- ### Execute GetCounter Script with Flow CLI Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Use this command to execute the GetCounter script located in the cadence/scripts directory. Ensure the Flow CLI is installed and configured. ```shell flow scripts execute cadence/scripts/GetCounter.cdc ``` -------------------------------- ### Get Account Information Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Retrieve account details, including deployed contracts if specified. Flow addresses must include the '0x' prefix. Account names can be used if a 'flow.json' is present. ```bash flow accounts get [--include contracts] [--network mainnet] ``` ```bash flow accounts get 0xe467b9dd11fa00df --network mainnet ``` ```bash flow accounts get 0xe467b9dd11fa00df --include contracts --network mainnet ``` ```bash flow accounts staking-info 0xe467b9dd11fa00df --network mainnet ``` -------------------------------- ### Import Statement in Cadence Script Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md This is an example of how to import a contract within a Cadence script. Ensure the contract 'Counter' is available in your project's scope. ```cadence import "Counter" ``` -------------------------------- ### Get Events by Type from Recent Blocks Source: https://context7.com/onflow/flow-cli/llms.txt Fetches events of a specified type from the last 10 blocks by default. Customize the event identifier as needed. ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited ``` -------------------------------- ### Get Block Events by Type Source: https://context7.com/onflow/flow-cli/llms.txt Retrieves events emitted by a specific contract within the latest block. Replace the event identifier with the desired one. ```bash flow blocks get latest --events A.f8d6e0586b0a20c7.HelloWorld.GreetingChanged ``` -------------------------------- ### Get Event Data in JSON Format Source: https://context7.com/onflow/flow-cli/llms.txt Retrieve event data in JSON format for easier parsing and integration with other tools. Use the --output json flag. ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited --output json ``` -------------------------------- ### Get Block Information Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Retrieve details about a specific block, optionally including associated transactions or events. Blocks can be identified by ID, height, or by using 'latest'. ```bash flow blocks get [--include transactions] [--events ] [--network mainnet] ``` ```bash flow blocks get latest --network mainnet ``` ```bash flow blocks get 12884163 --include transactions --network mainnet ``` ```bash flow blocks get latest --events A.1654653399040a61.FlowToken.TokensDeposited --network mainnet ``` -------------------------------- ### Get Events Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Fetch events emitted within a block range or the last N blocks. Multiple event types can be queried in parallel. Event names follow the format: A.
... ```bash flow events get [ ...] [--last 10] [--start N --end M] [--network mainnet] ``` ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited --last 20 --network mainnet ``` ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited --start 11559500 --end 11559600 --network mainnet ``` ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited A.1654653399040a61.FlowToken.TokensWithdrawn --network mainnet ``` -------------------------------- ### Get Events from Specific Block Range Source: https://context7.com/onflow/flow-cli/llms.txt Retrieves events of a given type within a specified block range (start and end block heights). ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited --start 11559500 --end 11559600 ``` -------------------------------- ### Get Transaction Information Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Retrieve details for regular, system, or scheduled transactions. System transactions are identified by block, while scheduled transactions use their numeric ID or account address. ```bash # Regular transaction flow transactions get [--include signatures,code,payload,fee-events] [--exclude events] [--network mainnet] ``` ```bash # System transaction (by block, not tx hash) flow transactions get-system [tx_id] [--network mainnet] ``` ```bash # Scheduled transactions flow schedule get [--network mainnet] flow schedule list [--network mainnet] ``` -------------------------------- ### Build and Run with Nix Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Builds the project using Nix and then executes the compiled binary. ```bash nix build ./result/bin/flow ``` -------------------------------- ### Enter Nix Development Shell Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Activates the Nix development environment, making project dependencies available. ```bash nix develop ``` -------------------------------- ### Initialize Flow Project Source: https://context7.com/onflow/flow-cli/llms.txt Use `flow init` to create a new Flow project or configure an existing directory. The command generates a `flow.json` file for project configuration. ```bash flow init my-project ``` ```bash flow init --config-only ``` ```json { "emulators": { "default": { "port": 3569, "serviceAccount": "emulator-account" } }, "contracts": { "HelloWorld": "cadence/contracts/HelloWorld.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": "YOUR_PRIVATE_KEY" } }, "deployments": { "emulator": { "emulator-account": ["HelloWorld"] } } } ``` -------------------------------- ### Get Transaction Status and Details Source: https://context7.com/onflow/flow-cli/llms.txt Use `flow transactions get` to retrieve the status and details of a submitted transaction by its ID. The `--include code` flag can show the transaction's code. ```bash flow transactions get abc123def456... --network testnet ``` ```bash flow transactions get abc123... --include code ``` -------------------------------- ### Get Latest Block Source: https://context7.com/onflow/flow-cli/llms.txt Retrieves information about the most recent block on the Flow blockchain. ```bash flow blocks get latest ``` -------------------------------- ### Specify Custom Configuration File Source: https://context7.com/onflow/flow-cli/llms.txt Use a custom configuration file instead of the default `flow.json`. Specify the path using the --config-path flag. ```bash flow accounts get 0x123 --config-path ./my-flow.json ``` -------------------------------- ### Save Account Information to File Source: https://context7.com/onflow/flow-cli/llms.txt Save the output of an account query directly to a file. Use the --save flag followed by the desired filename. ```bash flow accounts get 0x123 --save account.json ``` -------------------------------- ### Get Collection Information Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Retrieve the contents of a specific collection using its collection ID. ```bash flow collections get [--network mainnet] ``` -------------------------------- ### Build Flow CLI Binary Source: https://github.com/onflow/flow-cli/blob/master/CLAUDE.md Builds the Flow CLI binary using Go, enabling CGO for BLS crypto. Alternatively, use the Make command for a simpler build process. ```bash # Build the binary (requires CGO for BLS crypto) CGO_ENABLED=1 CGO_CFLAGS="-O2 -D__BLST_PORTABLE__ -std=gnu11" GO111MODULE=on go build -o ./cmd/flow/flow ./cmd/flow ``` ```bash # Or use Make make binary ``` -------------------------------- ### Output Account Information in Inline Format Source: https://context7.com/onflow/flow-cli/llms.txt Display account information on a single line for concise output. Use the --output inline flag. ```bash flow accounts get 0x123 --output inline ``` -------------------------------- ### Get Events from Last N Blocks Source: https://context7.com/onflow/flow-cli/llms.txt Fetches events of a specified type from a custom number of recent blocks. ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited --last 20 ``` -------------------------------- ### Deploy Project to Emulator Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Deploys your project contracts to the Flow Emulator network. Ensure the emulator is running before executing this command. ```shell flow project deploy --network=emulator ``` -------------------------------- ### Flow CLI Usage Overview Source: https://github.com/onflow/flow-cli/blob/master/README.md This displays the general usage and available command categories for the Flow CLI. It's useful for understanding the CLI's structure and capabilities. ```bash Usage: flow [command] 👋 Welcome Flow developer! If you are starting a new flow project use our super commands, start by running 'flow init'. 🔥 Super Commands generate Generate template files for common Cadence code init Start a new Flow project 📦 Flow Entities accounts Create and retrieve accounts and deploy contracts blocks Retrieve blocks collections Retrieve collections events Retrieve events 💬 Flow Interactions scripts Execute Cadence scripts transactions Build, sign, send and retrieve transactions 🔨 Flow Tools cadence Execute Cadence code dev-wallet Run a development wallet emulator Run Flow network for development flix execute, generate, package flowser Run Flowser project explorer test Run Cadence tests 🏄 Flow Project deploy Deploy all project contracts project Manage your Cadence project run Start emulator and deploy all project contracts 🔒 Flow Security keys Generate and decode Flow keys signatures Signature verification and creation 🔗 Dependency Manager dependencies Manage contracts and dependencies ``` -------------------------------- ### Get Delegator Info Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves detailed information about a specific delegator on a given node. Requires the FlowIDTableStaking contract. ```cadence import FlowIDTableStaking from 0x8624b52f9ddcd04a access(all) fun main(nodeID: String, delegatorID: UInt32): FlowIDTableStaking.DelegatorInfo { return FlowIDTableStaking.DelegatorInfo(nodeID: nodeID, delegatorID: delegatorID) } ``` -------------------------------- ### Deploy All Project Contracts Source: https://context7.com/onflow/flow-cli/llms.txt The `flow deploy` command deploys all contracts defined in the `flow.json` configuration file. It can target specific networks and update existing contracts. ```bash flow deploy ``` ```bash flow deploy --network testnet ``` ```bash flow deploy --update ``` -------------------------------- ### Get Delegator Reward Cut Percentage Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the percentage of rewards that are cut from delegators. Requires the FlowIDTableStaking contract. ```cadence import FlowIDTableStaking from 0x8624b52f9ddcd04a access(all) fun main(): UFix64 { return FlowIDTableStaking.getRewardCutPercentage() } ``` -------------------------------- ### Display Account Information in JSON Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md This snippet demonstrates the JSON output format for account details, which is useful for programmatic consumption and integration with other tools. It includes address, balance, code, and key information. ```json {"Address":"179b6b1cb6755e31","Balance":0,"Code":"CnB1YiBjb250cmFjdCBGb28gewoJcHViIHZhciBiYXI6IFN0cmluZwoKCWluaXQoKSB7CgkJc2VsZi5iYXIgPSAiSGVsbG8sIFdvcmxkISIKCX0KfQo=","Keys":[{"Index":0,"PublicKey":{},"SigAlgo":2,"HashAlgo":3,"Weight":1000,"SequenceNumber":0,"Revoked":false}],"Contracts":null} ``` -------------------------------- ### Get Latest Random Beacon Source Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the most recent source of randomness from the beacon history. Requires the RandomBeaconHistory contract. ```cadence import RandomBeaconHistory from 0xe467b9dd11fa00df access(all) fun main(): RandomBeaconHistory.RandomSourceHistoryEntry { return RandomBeaconHistory.getLatestSourceOfRandomness() } ``` -------------------------------- ### Output Account Information in JSON Format Source: https://context7.com/onflow/flow-cli/llms.txt Display account information in JSON format for structured data processing. Use the --output json flag. ```bash flow accounts get 0x123 --output json ``` -------------------------------- ### Create a New Flow Account Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md This command is used to create a new Flow account. Ensure your deployment targets are configured in `flow.json` before deploying. ```shell flow accounts create ``` -------------------------------- ### Get All Delegator Info for an Account Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves all delegator information associated with a Flow account address. Requires the FlowStakingCollection contract. ```cadence import FlowStakingCollection from 0x8d0e87b65159ae63 access(all) fun main(address: Address): [FlowStakingCollection.DelegatorInfo] { return FlowStakingCollection.getAllDelegatorInfo(address: address) } ``` -------------------------------- ### Get Weekly Epoch Reward Payout Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the total token payout for the current epoch. Requires the FlowIDTableStaking contract. ```cadence import FlowIDTableStaking from 0x8624b52f9ddcd04a access(all) fun main(): UFix64 { return FlowIDTableStaking.getEpochTokenPayout() } ``` -------------------------------- ### Linting and Code Generation Source: https://github.com/onflow/flow-cli/blob/master/CLAUDE.md Commands for linting the codebase using golangci-lint, auto-fixing lint issues, verifying license headers, and regenerating code. ```bash make lint # Run golangci-lint ``` ```bash make fix-lint # Auto-fix lint issues ``` ```bash make check-headers # Verify Apache license headers on all Go files ``` ```bash go generate ./... # Regenerate generated code (required before lint) ``` -------------------------------- ### Display Account Information Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md This snippet shows the default output format for account details, including address, balance, keys, and contract code. It is designed for human readability and compatibility with command-line tools. ```text Address 179b6b1cb6755e31 Balance 0 Keys 2 Key 0 Public Key c8a2a318b9099cc6c872a0ec3dcd9f59d17837e4ffd6cd8a1f913ddfa769559605e1ad6ad603ebb511f5a6c8125f863abc2e9c600216edaa07104a0fe320dba7 Weight 1000 Signature Algorithm ECDSA_P256 Hash Algorithm SHA3_256 Code access(all) contract Foo { access(all) var bar: String init() { self.bar = "Hello, World!" } } ``` -------------------------------- ### Get Block by ID Source: https://context7.com/onflow/flow-cli/llms.txt Retrieves block information using its unique identifier. Replace `abc123def456...` with the actual block ID. ```bash flow blocks get abc123def456... ``` -------------------------------- ### Run Tests with Coverage Report Source: https://context7.com/onflow/flow-cli/llms.txt Runs tests and generates a coverage report. This helps in identifying untested code sections. ```bash flow test --cover ``` -------------------------------- ### Get All Node Info for an Account Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves all staking node information associated with a Flow account address. Requires the FlowStakingCollection contract. ```cadence import FlowStakingCollection from 0x8d0e87b65159ae63 access(all) fun main(address: Address): [FlowStakingCollection.NodeInfo] { return FlowStakingCollection.getAllNodeInfo(address: address) } ``` -------------------------------- ### Fetch Multiple Event Types in Parallel Source: https://context7.com/onflow/flow-cli/llms.txt Use this command to fetch multiple event types concurrently. Specify the event names separated by spaces. ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited \ A.1654653399040a61.FlowToken.TokensWithdrawn ``` -------------------------------- ### Run Tests with Custom Fork Host Source: https://context7.com/onflow/flow-cli/llms.txt Allows specifying a custom host for forking network states. Useful for testing against specific node endpoints. ```bash flow test --fork-host access.mainnet.nodes.onflow.org:9000 ``` -------------------------------- ### Generate New Contract with Test File Source: https://context7.com/onflow/flow-cli/llms.txt Creates a new Cadence contract file and its corresponding test file. Follows Flow best practices and registers the contract in project configuration. ```bash flow generate contract HelloWorld ``` -------------------------------- ### Direct Host Connection for Account Query Source: https://context7.com/onflow/flow-cli/llms.txt Connect directly to a specific Flow network node using the --host flag. This bypasses default network configurations. ```bash flow accounts get 0x123 --host access.mainnet.nodes.onflow.org:9000 ``` -------------------------------- ### Run the Flow CLI Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md Execute the Flow CLI application directly using the Go run command. ```bash go run cmd/flow/main.go ``` -------------------------------- ### Execute Cadence Script with Flow CLI Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Use the Flow CLI to execute a Cadence script from a local file path. Specify the network and any required arguments. ```bash git clone --depth 1 https://github.com/onflow/flow-core-contracts.git /tmp/flow-core-contracts flow scripts execute /tmp/flow-core-contracts/transactions/idTableStaking/scripts/get_node_info.cdc "abc123...def456" --network mainnet ``` -------------------------------- ### Cadence Import Styles Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Illustrates two ways to import Cadence contracts. The 'Repo style' requires address mappings in `flow.json`, while the 'Direct style' uses explicit addresses. ```cadence // Repo style (requires flow.json aliases): import "FlowToken" // Direct style (works without flow.json): import FlowToken from 0x1654653399040a61 ``` -------------------------------- ### Get NFT Collection IDs Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves all NFT IDs within a specified collection for an account. Requires NonFungibleToken contract and a valid public path to the collection. ```cadence import NonFungibleToken from 0x1d7e57aa55817448 access(all) fun main(address: Address, collectionPublicPath: PublicPath): [UInt64] { let account = getAccount(address) let collectionRef = account.capabilities .borrow<&{NonFungibleToken.Collection}>(collectionPublicPath) ?? panic("Could not borrow NonFungibleToken Collection capability for account \(address) at path \(collectionPublicPath). Make sure the account has an NFT Collection set up at this path.") return collectionRef.getIDs() } ``` -------------------------------- ### Deploy Project to Testnet Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Deploys your project contracts to the Flow Testnet. This command allows interaction with your project on the Testnet. ```shell flow project deploy --network=testnet ``` -------------------------------- ### Get NFT Metadata (Display) Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the display metadata for a specific NFT within a collection. Requires NonFungibleToken and MetadataViews contracts, and a valid public path to the collection. ```cadence import NonFungibleToken from 0x1d7e57aa55817448 import MetadataViews from 0x1d7e57aa55817448 access(all) fun main(address: Address, collectionPublicPath: PublicPath, id: UInt64): MetadataViews.Display? { let account = getAccount(address) let collectionRef = account.capabilities .borrow<&{NonFungibleToken.Collection}>(collectionPublicPath) ?? panic("Could not borrow NonFungibleToken Collection capability for account \(address) at path \(collectionPublicPath). Make sure the account has an NFT Collection set up at this path.") let nft = collectionRef.borrowNFT(id)! return MetadataViews.getDisplay(nft) } ``` -------------------------------- ### Skip Interactive Confirmations Source: https://context7.com/onflow/flow-cli/llms.txt Execute commands like `flow deploy` without requiring interactive confirmation. Use the --yes flag to automatically confirm. ```bash flow deploy --yes ``` -------------------------------- ### Generated Contract Template Source: https://context7.com/onflow/flow-cli/llms.txt A basic template for a Cadence contract, including the `init()` function. ```cadence access(all) contract HelloWorld { init() {} } ``` -------------------------------- ### Run Specific Test Files Source: https://context7.com/onflow/flow-cli/llms.txt Executes only the specified Cadence test files. Provide the paths to the test files. ```bash flow test ./cadence/tests/HelloWorld_test.cdc ./cadence/tests/Token_test.cdc ``` -------------------------------- ### Query FT Metadata (Display Info) Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Fetches display information (like name, symbol, decimals) for a Fungible Token (FT) vault at a specified public path. Requires FungibleToken and FungibleTokenMetadataViews contracts. ```cadence import FungibleToken from 0xf233dcee88fe0abe import FungibleTokenMetadataViews from 0xf233dcee88fe0abe access(all) fun main(address: Address, vaultPath: PublicPath): FungibleTokenMetadataViews.FTDisplay? { let account = getAccount(address) let vaultRef = account.capabilities .borrow<&{FungibleToken.Vault}>(vaultPath) ?? panic("Could not borrow FungibleToken Vault capability for account \(address) at path \(vaultPath). Make sure the account has a Fungible Token Vault set up at this path.") return FungibleTokenMetadataViews.getFTDisplay(vaultRef) } ``` -------------------------------- ### Deploy Project to Mainnet Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Deploys your project contracts to the Flow Mainnet. This command enables interaction with your project on the Mainnet. ```shell flow project deploy --network=mainnet ``` -------------------------------- ### Generated Script Template Source: https://context7.com/onflow/flow-cli/llms.txt A basic template for a Cadence script, containing a `main` function. ```cadence access(all) fun main() {} ``` -------------------------------- ### Set Log Level to Debug Source: https://context7.com/onflow/flow-cli/llms.txt Enable debug logging for detailed output during command execution. Use the --log debug flag. ```bash flow --log debug accounts get 0x123 ``` -------------------------------- ### Query Epoch Timing Configuration Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the timing configuration for epochs on the Flow network. Requires the FlowEpoch contract. ```cadence import FlowEpoch from 0x8624b52f9ddcd04a access(all) fun main(): FlowEpoch.EpochTimingConfig { return FlowEpoch.getEpochTimingConfig() } ``` -------------------------------- ### Run Project Tests Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Execute all tests with the `_test.cdc` suffix. These are typically located in the `cadence/tests` folder. You can add more tests using `flow generate test`. ```shell flow test ``` -------------------------------- ### Run Flow CLI Directly Source: https://github.com/onflow/flow-cli/blob/master/CLAUDE.md Executes the Flow CLI commands directly using `go run` without building a separate binary. Useful for quick command execution. ```bash go run cmd/flow/main.go [command] ``` -------------------------------- ### Generate Test File Source: https://context7.com/onflow/flow-cli/llms.txt Creates a new Cadence test file for an existing contract or for general testing purposes. ```bash flow generate test HelloWorld ``` -------------------------------- ### Run All Flow CLI Tests Source: https://github.com/onflow/flow-cli/blob/master/CLAUDE.md Executes all tests within the Flow CLI project, generating a coverage profile. This is equivalent to using the `make test` command. ```bash # Run all tests make test # Equivalent: CGO_ENABLED=1 CGO_CFLAGS="-O2 -D__BLST_PORTABLE__ -std=gnu11" GO111MODULE=on go test -coverprofile=coverage.txt ./... ``` -------------------------------- ### Deploy Contract to Account Source: https://context7.com/onflow/flow-cli/llms.txt Use `flow accounts add-contract` to deploy a Cadence contract to a specified Flow account. You can include initialization arguments or use JSON-Cadence formatted arguments. ```bash flow accounts add-contract ./cadence/contracts/HelloWorld.cdc ``` ```bash flow accounts add-contract ./cadence/contracts/Token.cdc "arg1" "arg2" ``` ```bash flow accounts add-contract ./cadence/contracts/Token.cdc \ --args-json '[{"type": "String", "value": "MyToken"}]' ``` ```bash flow accounts add-contract ./cadence/contracts/HelloWorld.cdc --signer my-account ``` -------------------------------- ### Run Specific Test Package Source: https://github.com/onflow/flow-cli/blob/master/CLAUDE.md Executes tests for a particular package within the Flow CLI. Ensure CGO is enabled for BLS crypto compatibility. ```bash CGO_ENABLED=1 CGO_CFLAGS="-O2 -D__BLST_PORTABLE__ -std=gnu11" go test ./internal/accounts/... ``` -------------------------------- ### Exit Status Convention Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md The CLI should return a zero exit status on success and non-zero on error, facilitating command chaining and integration with other tools. Instructions for exiting long-running commands should be provided. ```text exit status 1 ``` -------------------------------- ### Run Tests Forked from Mainnet Source: https://context7.com/onflow/flow-cli/llms.txt Tests are run against a forked state of the mainnet. This allows for testing against live network conditions without affecting the live network. ```bash flow test --fork mainnet ``` -------------------------------- ### Execute Cadence Script with Arguments Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/SKILL.md Use `flow scripts execute` to run a Cadence script. Arguments can be passed as simple types positionally or as complex types using JSON encoding with `--args-json`. Historical state can be queried using `--block-height` or `--block-id`. ```bash flow scripts execute [args...] [--args-json '[{"type":"...","value":"..."}]'] [--block-height N] [--block-id ] [--network mainnet] ``` ```bash # Write cat > /tmp/query.cdc << 'EOF' import FungibleToken from 0xf233dcee88fe0abe import FlowToken from 0x1654653399040a61 access(all) fun main(address: Address): UFix64 { let account = getAccount(address) let vaultRef = account.capabilities .borrow<&{FungibleToken.Balance}>(/public/flowTokenBalance) ?? panic("Could not borrow FungibleToken Balance capability for account \(address) at path /public/flowTokenBalance. Make sure the account has a FlowToken Vault set up properly.") return vaultRef.balance } EOF # Execute flow scripts execute /tmp/query.cdc 0xe467b9dd11fa00df --network mainnet # Clean up rm /tmp/query.cdc ``` ```bash # Simple types as positional args flow scripts execute /tmp/query.cdc 0xe467b9dd11fa00df --network mainnet ``` ```bash # Complex types with --args-json (JSON-Cadence encoding) flow scripts execute /tmp/query.cdc --args-json '[{"type":"UFix64","value":"100.0"},{"type":"Address","value":"0xe467b9dd11fa00df"}]' --network mainnet ``` ```bash # Historical state flow scripts execute /tmp/query.cdc 0xe467b9dd11fa00df --block-height 12884163 --network mainnet ``` -------------------------------- ### Generate Code in Specific Directory Source: https://context7.com/onflow/flow-cli/llms.txt Generates contract, transaction, script, or test files within a specified directory. This helps organize project structure. ```bash flow generate contract MyContract --dir ./cadence/contracts ``` -------------------------------- ### Configure Workers for Parallel Event Fetching Source: https://context7.com/onflow/flow-cli/llms.txt Optimize parallel event fetching by configuring the number of workers and batch size. This can improve performance for large-scale data retrieval. ```bash flow events get A.1654653399040a61.FlowToken.TokensDeposited \ --workers 10 --batch 25 ``` -------------------------------- ### Query Generic FT Balance by Path Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the balance of any Fungible Token (FT) for a given account address and public vault path. This script requires the FungibleToken contract. ```cadence import FungibleToken from 0xf233dcee88fe0abe access(all) fun main(address: Address, path: PublicPath): UFix64 { return getAccount(address).capabilities .borrow<&{FungibleToken.Balance}>(path)?.balance ?? panic("Could not borrow FungibleToken Balance capability for account \(address) at path \(path). Make sure the account has a Fungible Token Vault set up at this path.") } ``` -------------------------------- ### Set Log Level to Info Source: https://context7.com/onflow/flow-cli/llms.txt Set the log level to 'info' for standard operational messages. This is useful for monitoring emulator or test runs. ```bash flow --log info emulator ``` -------------------------------- ### Output Signature in JSON Format Source: https://context7.com/onflow/flow-cli/llms.txt Generate a signature and output the result in JSON format. This is convenient for programmatic handling of signature data. ```bash flow signatures generate "Hello Flow!" --signer my-account --output json ``` -------------------------------- ### Handle Connection Refused Error Source: https://github.com/onflow/flow-cli/blob/master/CONTRIBUTING.md This snippet shows a typical error message when the CLI cannot connect to the Flow emulator. It includes a human-readable error and a suggestion for resolution, directing output to stderr. ```text ❌ Error while dialing dial tcp 127.0.0.1:3569: connect: connection refused" 🙏 Make sure your emulator is running or connection address is correct. ``` -------------------------------- ### Generate New Transaction with Flow CLI Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Run this command to create a new Cadence transaction file. Transactions are used to modify the blockchain state and can import dependencies. ```shell flow generate transaction ``` -------------------------------- ### Manage Flow Accounts Source: https://context7.com/onflow/flow-cli/llms.txt The `flow accounts` commands facilitate account management, including retrieving account information, creating new accounts, funding accounts on testnet, and listing accounts defined in `flow.json`. Supports various options for key configuration and output formats. ```bash flow accounts get f8d6e0586b0a20c7 ``` ```bash flow accounts get my-account ``` ```bash flow accounts get f8d6e0586b0a20c7 --include contracts ``` ```bash flow accounts create --key "PUBLIC_KEY_HEX" ``` ```bash flow accounts create --key "PUBLIC_KEY_HEX" --signer emulator-account ``` ```bash flow accounts create \ --key "KEY1_HEX" --key "KEY2_HEX" \ --key-weight 500 --key-weight 500 \ --sig-algo ECDSA_P256 --sig-algo ECDSA_P256 \ --hash-algo SHA3_256 --hash-algo SHA3_256 ``` ```bash flow accounts fund f8d6e0586b0a20c7 --network testnet ``` ```bash flow accounts list ``` ```bash flow accounts staking-info f8d6e0586b0a20c7 --network mainnet ``` ```bash flow accounts get f8d6e0586b0a20c7 --output json ``` ```json { "address": "f8d6e0586b0a20c7", "balance": "1000000.00000000", "keys": ["abc123..."], ``` -------------------------------- ### Query Current Epoch Phase Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Retrieves the current phase of the epoch cycle (e.g., StakingAuction, EpochSetup, EpochCommit). Requires the FlowEpoch contract. ```cadence import FlowEpoch from 0x8624b52f9ddcd04a // Returns: 0=StakingAuction, 1=EpochSetup, 2=EpochCommit access(all) fun main(): UInt8 { return FlowEpoch.currentEpochPhase.rawValue } ``` -------------------------------- ### Query Account Storage Capacity Source: https://github.com/onflow/flow-cli/blob/master/skills/query-blockchain/cadence-scripts.md Calculates the storage capacity of a given Flow account address. This script requires the FlowStorageFees contract. ```cadence import FlowStorageFees from 0xe467b9dd11fa00df access(all) fun main(address: Address): UFix64 { return FlowStorageFees.calculateAccountCapacity(address) } ``` -------------------------------- ### Build and Sign Transactions Source: https://context7.com/onflow/flow-cli/llms.txt The `flow transactions build` command creates an unsigned transaction payload, which can then be signed using `flow transactions sign` and sent using `flow transactions send-signed`. ```bash flow transactions build ./cadence/transactions/Transfer.cdc "0x123" "10.0" \ --proposer my-account --payer my-account --authorizer my-account ``` ```bash flow transactions sign ./unsigned-tx.rlp --signer my-account ``` ```bash flow transactions send-signed ./signed-tx.rlp ``` -------------------------------- ### Generated Test Template Source: https://context7.com/onflow/flow-cli/llms.txt A minimal template for a Cadence test file, ready for implementing test cases. ```cadence import Test import "HelloWorld" access(all) fun testExample() { // Test implementation } ``` -------------------------------- ### Generate New Test with Flow CLI Source: https://github.com/onflow/flow-cli/blob/master/internal/super/generator/fixtures/README_with_deps.md Use this command to create a new Cadence test file. Tests are essential for verifying the functionality of your contracts, scripts, and transactions. ```shell flow generate test ```