LLM Notice: This documentation site supports content negotiation for AI agents. Request any page with Accept: text/markdown or Accept: text/plain header to receive Markdown instead of HTML. Alternatively, append ?format=md to any URL. All markdown files are available at /md/ prefix paths. For all content in one file, visit /llms-full.txt
Skip to main content

Add Project Contracts

Generate a Contract

Create a new contract file using the Flow CLI:


_10
flow generate contract Foo

This command creates cadence/contracts/Foo.cdc with a basic contract template and automatically adds it to your flow.json configuration.

Add a Contract to Configuration

If you have an existing contract file, add it to your project configuration using the CLI:


_10
flow config add contract

Follow the interactive prompts:

  1. Contract name: Enter the contract name (e.g., Foo)
  2. Contract filename: Enter the path to your contract file (e.g., ./cadence/contracts/Foo.cdc)
  3. Add aliases: Optionally add network aliases for dependencies

You can also use flags to specify all details at once:


_10
flow config add contract \
_10
--name Foo \
_10
--filename ./cadence/contracts/Foo.cdc

What gets added to flow.json:


_10
{
_10
"contracts": {
_10
"Foo": "./cadence/contracts/Foo.cdc"
_10
}
_10
}

Configure Contract Deployment Targets

Once a contract is added to your configuration, configure deployment targets using the CLI:


_10
flow config add deployment

Follow the interactive prompts:

  1. Network: Select the network (e.g., testnet, mainnet, emulator)
  2. Account: Select the account to deploy to (e.g., my-testnet-account)
  3. Contract: Select the contract to deploy (e.g., Foo)
  4. Deploy more contracts: Choose yes to add additional contracts to the same deployment

You can also use flags to specify all details:


_10
flow config add deployment \
_10
--network testnet \
_10
--account my-testnet-account \
_10
--contract Foo

What gets added to flow.json:


_10
{
_10
"deployments": {
_10
"testnet": {
_10
"my-testnet-account": ["Foo"]
_10
}
_10
}
_10
}

Add Multiple Contracts to a Deployment

To deploy multiple contracts to the same account, run the deployment configuration command multiple times or use the interactive prompt to add more contracts:


_10
flow config add deployment --network testnet --account my-testnet-account --contract Bar

This adds Bar to the existing deployment:


_10
{
_10
"deployments": {
_10
"testnet": {
_10
"my-testnet-account": ["Foo", "Bar"]
_10
}
_10
}
_10
}

Remove Contracts and Deployments

Remove contracts or deployments using the CLI:


_10
# Remove a contract from configuration
_10
flow config remove contract Foo
_10
_10
# Remove a contract from a specific deployment
_10
flow config remove deployment testnet my-testnet-account Foo

Best Practices

  • Use CLI commands: Always use flow config add and flow config remove instead of manually editing flow.json
  • Generate contracts: Use flow generate contract to create new contracts with proper structure
  • Verify configuration: Use flow accounts list and check your flow.json to verify your configuration
  • Network-specific deployments: Configure separate deployments for each network (emulator, testnet, mainnet)

For more information, see Manage Configuration and Production Deployment.