Skip to main content

Cadence Environment Setup

This comprehensive tutorial will guide you through setting up your complete development environment, deploying your first smart contract, and mastering the fundamentals of Flow development. You'll work hands-on with the Flow CLI, local emulator, and a real smart contract to build practical skills from day one.

Flow is a blockchain built for the next generation of apps, games, and digital assets. With its unique multi-role architecture and resource-oriented programming language Cadence, Flow enables developers to create secure, composable, and scalable applications. This tutorial focuses on getting you productive with Flow's developer tools as quickly as possible.

What You'll Learn

After completing this tutorial, you'll be able to:

  • Set up a complete Flow development environment with CLI tools and VSCode integration
  • Create and manage Flow projects using the Flow CLI and understand project structure
  • Deploy and interact with smart contracts on the local Flow emulator
  • Execute scripts and transactions to read from and modify blockchain state
  • Understand Flow's account model and how contracts are deployed to account storage
  • Navigate the Flow ecosystem and know where to find help and resources

What You'll Build

You'll work with a Counter contract—a simple but comprehensive example that demonstrates core Flow development patterns. This contract maintains a count value and provides functions to increment, decrement, and read the current count. By the end of this tutorial, you'll have:

  • A fully functional local Flow development environment
  • A deployed Counter contract running on your local emulator
  • Scripts to query the contract's state
  • Transactions to modify the contract's state
  • Understanding of how to extend this foundation for more complex applications

Time Commitment: Approximately 30-45 minutes

Prerequisites:

  • Basic command line familiarity
  • Code editor (VSCode recommended)
  • Node.js installed (for future frontend development)

Install Flow CLI

The Flow Command Line Interface (CLI) is a set of tools that developers can use to interact with the Flow blockchain by managing accounts, sending transactions, deploying smart contracts, running the emulator, and more. This quickstart will get you familiar with its main concepts and functionality.

The first thing you'll need to do is install the Flow CLI. If you have homebrew installed you can run:


_10
brew install flow-cli

For other operating systems, please refer to the installation guide for detailed instructions.

Verify Installation:


_10
flow version

You should see output showing your Flow CLI version.

Install VSCode Extension

Install the Flow Cadence VSCode Extension from the marketplace. This extension provides:

  • Syntax highlighting for Cadence
  • Code completion and IntelliSense
  • Error checking and diagnostics
  • Integrated development tools

Create Your First Project

Navigate to your desired development directory and create a new Flow project:


_10
flow init

When prompted:

  1. Project name: Enter your preferred project name
  2. Install core contracts: Select No for this tutorial

The flow init command creates:

  • flow.json: Central configuration file containing accounts, contracts, deployments, and network settings
  • emulator-account.pkey: Private key for the default emulator account
  • cadence/: Directory structure for your Cadence code:
    • contracts/: Smart contract files
    • scripts/: Read-only blockchain queries
    • transactions/: State-changing operations
    • tests/: Contract test files

Navigate into your project directory:


_10
cd your-flow-project-name

info

For additional details on how flow.json is configured, review the configuration docs.

Start the Flow Emulator

The emulator is a local version of the Flow blockchain that you can use to test your contracts and scripts. It's a great way to develop and test your contracts locally - before you try them on the testnet or mainnet.

Before we deploy, let's open a new terminal window and run the emulator. From the root of your project directory, where your emulator-account.pkey and flow.json files are located, run:


_10
flow emulator start

Keep this terminal running. The emulator provides:

  • Local blockchain environment
  • Fast transaction processing
  • No real-world costs
  • Complete Flow feature set

Your First Contract

Now let's examine, deploy, and interact with the Counter contract that was created in your project.

Examine the Counter Contract

Open cadence/contracts/Counter.cdc in your editor. Let's break down this contract:


_31
access(all) contract Counter {
_31
_31
access(all) var count: Int
_31
_31
// Event to be emitted when the counter is incremented
_31
access(all) event CounterIncremented(newCount: Int)
_31
_31
// Event to be emitted when the counter is decremented
_31
access(all) event CounterDecremented(newCount: Int)
_31
_31
init() {
_31
self.count = 0
_31
}
_31
_31
// Public function to increment the counter
_31
access(all) fun increment() {
_31
self.count = self.count + 1
_31
emit CounterIncremented(newCount: self.count)
_31
}
_31
_31
// Public function to decrement the counter
_31
access(all) fun decrement() {
_31
self.count = self.count - 1
_31
emit CounterDecremented(newCount: self.count)
_31
}
_31
_31
// Public function to get the current count
_31
view access(all) fun getCount(): Int {
_31
return self.count
_31
}
_31
}

Key Components:

  • Contract Declaration: access(all) contract Counter creates a public contract named Counter

  • State Variable: access(all) var count: Int stores the counter value, accessible to everyone

  • Events: CounterIncremented and CounterDecremented notify listeners when changes occur

  • Initializer: init() sets the initial count to 0 when the contract is deployed

  • Public Functions:

    • increment(): Increases count by 1 and emits an event
    • decrement(): Decreases count by 1 and emits an event
    • getCount(): Returns the current count (read-only, marked with view)

Create and Configure Deployment Account

When you created a project you'll see that a Counter contract was added to your flow.json configuration file, but it's not set up for deployment yet. We could deploy it to the automatically created emulator-account, but for this example lets also create a new account on the emulator to deploy it to.

info

Reminder: On Flow Cadence, contracts are deployed to the storage of the account that deploys them.

Leave your emulator running, and open a second terminal. Run the following command:


_10
flow accounts create

When prompted:

  1. Account name: Enter test-account
  2. Network: Select Emulator

This adds the new account to your flow.json configuration file.You'll now see this account in your flow.json.

Once you have created you accounts, then you can view all your accounts on the with the Flow CLI with:


_24
📋 Account Status Across Networks
_24
_24
This shows which networks your configured accounts are accessible on:
_24
🌐 Network 🟢 Local (running) 🔴 Local (stopped) ✓ Found ✗ Error
_24
─────────────────────────────────────────────────────
_24
_24
🟢 emulator
_24
✓ default (f3fcd2c1a78f5eee): 0.00100000 FLOW
_24
✓ emulator-account (f8d6e0586b0a20c7): 999999999.99300000 FLOW
_24
✓ test-account (e03daebed8ca0615): 0.00100000 FLOW
_24
_24
🌐 mainnet
_24
No accounts found
_24
_24
🌐 testnet
_24
No accounts found
_24
_24
🟢 testing
_24
✓ default (f3fcd2c1a78f5eee): 0.00100000 FLOW
_24
✓ emulator-account (f8d6e0586b0a20c7): 999999999.99300000 FLOW
_24
✓ test-account (e03daebed8ca0615): 0.00100000 FLOW
_24
_24
_24
💡 Tip: To fund testnet accounts, run: flow accounts fund

This is a great tool to visualize your different accounts and balances when you are developing.

Configure Contract Deployment

To deploy the Counter contract to the emulator, you'll need to add it to your project configuration. You can do this by running:


_10
flow config add deployment

Follow the prompts:

  1. Network: Select emulator
  2. Account: Select test-account
  3. Contract: Select Counter
  4. Deploy more contracts: Select no

This configures your flow.json to deploy the Counter contract to your test account on the emulator.

Deploy the Contract

To deploy the Counter contract to the emulator, run:


_10
flow project deploy

You should see output similar to:


_10
Deploying 1 contracts for accounts: test-account
_10
_10
Counter -> 0x179b6b1cb6755e31 (a98c155fe7afc8eb2af5551748759b08a80a0ae85d1b09f92f1afc293c61ca98)
_10
_10
🎉 All contracts deployed successfully

That's it! You've just deployed your first contract to the Flow Emulator.

Verify Deployment with a Script

Scripts are used to read data from the Flow blockchain. There is no state modification. Let's verify the deployment by reading the counter value. Run the included script:


_10
flow scripts execute cadence/scripts/GetCounter.cdc

You should see:


_10
Result: 0

This confirms your contract is deployed and functioning correctly. The counter starts at 0, as defined in the contract's init() function.

If we wanted to generate a new script, we could run:


_10
flow generate script ScriptName

info

For more information about generating Cadence files, see the Generating Cadence Boilerplate documentation.

You'll usually want to use these commands instead of adding files manually!

tip

If you'll like to learn more about writing scripts, please check out the docs for basic scripts.

Executing Transactions

Now let's increment the counter using a transaction:


_10
flow transactions send cadence/transactions/IncrementCounter.cdc

By default, this uses the emulator-account to sign the transaction and the emulator network. If you want to use your test-account account, you can specify the --signer flag with the account name. The command would look like this:


_10
flow transactions send cadence/transactions/IncrementCounter.cdc --signer test-account

The transaction output shows detailed information including:

  • Transaction ID and block information
  • Status confirmation (✅ SEALED)
  • Events emitted (including CounterIncremented)

_33
Transaction ID: 9cc7ac4d3d5239016965aba89b9692d3401a48a090d1ad1a8d9ef9cfca685e6e
_33
_33
Block ID b8537860b0fc9ca8b3195b121e762502f9a220874b605d6a810998e8b62321a3
_33
Block Height 3
_33
Status ✅ SEALED
_33
ID 9cc7ac4d3d5239016965aba89b9692d3401a48a090d1ad1a8d9ef9cfca685e6e
_33
Payer f8d6e0586b0a20c7
_33
Authorizers [f8d6e0586b0a20c7]
_33
_33
Proposal Key:
_33
Address f8d6e0586b0a20c7
_33
Index 0
_33
Sequence 1
_33
_33
No Payload Signatures
_33
_33
Envelope Signature 0: f8d6e0586b0a20c7
_33
Signatures (minimized, use --include signatures)
_33
_33
Events:
_33
Index 0
_33
Type A.179b6b1cb6755e31.Counter.CounterIncremented
_33
Tx ID 9cc7ac4d3d5239016965aba89b9692d3401a48a090d1ad1a8d9ef9cfca685e6e
_33
Values
_33
- newCount (Int): 1
_33
_33
_33
_33
Code (hidden, use --include code)
_33
_33
Payload (hidden, use --include payload)
_33
_33
Fee Events (hidden, use --include fee-events)

Run the script to check the counter again. You'll see that it has incremented:


_10
flow scripts execute cadence/scripts/GetCounter.cdc


_10
Result: 1

tip

If you want to learn more about writing transactions, please read the docs for basic transactions.

Conclusion

You've successfully established a solid foundation for building on Flow. Let's recap what you've accomplished and learned. Through this hands-on tutorial, you've successfully built a complete Flow development foundation:

Complete Flow Development Environment

  • Flow CLI installed and configured for project management
  • Local Flow emulator running and ready for development
  • Project creation and management workflow with flow init

Smart Contract Deployment Skills

  • Counter contract successfully deployed to your local emulator
  • Account creation and contract deployment configuration mastered

Blockchain Interactions

  • Scripts to query contract state (reading blockchain data)
  • Transactions to modify contract state (writing to blockchain)
  • Real-time interaction with blockchain data through CLI commands

Resources for Continued Learning

As you continue your Flow development journey:

The foundation you've built today will serve you well as you explore Flow's capabilities and build applications that take advantage of blockchain's unique properties: permanence, transparency, and decentralization.

Welcome to the Flow developer community—you're ready to build the future of digital experiences!