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:
_10brew install flow-cli
For other operating systems, please refer to the installation guide for detailed instructions.
Verify Installation:
_10flow 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:
_10flow init
When prompted:
- Project name: Enter your preferred project name
- Install core contracts: Select
No
for this tutorial
The flow init
command creates:
flow.json
: Central configuration file containing accounts, contracts, deployments, and network settingsemulator-account.pkey
: Private key for the default emulator accountcadence/
: Directory structure for your Cadence code:contracts/
: Smart contract filesscripts/
: Read-only blockchain queriestransactions/
: State-changing operationstests/
: Contract test files
Navigate into your project directory:
_10cd your-flow-project-name
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:
_10flow 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:
_31access(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
andCounterDecremented
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 eventdecrement()
: Decreases count by 1 and emits an eventgetCount()
: Returns the current count (read-only, marked withview
)
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.
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:
_10flow accounts create
When prompted:
- Account name: Enter
test-account
- 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_24This 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:
_10flow config add deployment
Follow the prompts:
- Network: Select
emulator
- Account: Select
test-account
- Contract: Select
Counter
- 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:
_10flow project deploy
You should see output similar to:
_10Deploying 1 contracts for accounts: test-account_10_10Counter -> 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:
_10flow scripts execute cadence/scripts/GetCounter.cdc
You should see:
_10Result: 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:
_10flow generate script ScriptName
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!
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:
_10flow 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:
_10flow 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
)
_33Transaction ID: 9cc7ac4d3d5239016965aba89b9692d3401a48a090d1ad1a8d9ef9cfca685e6e_33_33Block ID b8537860b0fc9ca8b3195b121e762502f9a220874b605d6a810998e8b62321a3_33Block Height 3_33Status ✅ SEALED_33ID 9cc7ac4d3d5239016965aba89b9692d3401a48a090d1ad1a8d9ef9cfca685e6e_33Payer f8d6e0586b0a20c7_33Authorizers [f8d6e0586b0a20c7]_33_33Proposal Key:_33 Address f8d6e0586b0a20c7_33 Index 0_33 Sequence 1_33_33No Payload Signatures_33_33Envelope Signature 0: f8d6e0586b0a20c7_33Signatures (minimized, use --include signatures)_33_33Events:_33 Index 0_33 Type A.179b6b1cb6755e31.Counter.CounterIncremented_33 Tx ID 9cc7ac4d3d5239016965aba89b9692d3401a48a090d1ad1a8d9ef9cfca685e6e_33 Values_33 - newCount (Int): 1_33_33_33_33Code (hidden, use --include code)_33_33Payload (hidden, use --include payload)_33_33Fee Events (hidden, use --include fee-events)
Run the script to check the counter again. You'll see that it has incremented:
_10flow scripts execute cadence/scripts/GetCounter.cdc
_10Result: 1
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:
- Flow Discord Community: Connect with other developers, get help, and share your projects
- Cadence Language Reference: Deep dive into Flow's programming language features and best practices
- Flow GitHub: Explore open source tools, examples, and contribute to the ecosystem
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!