Deploying Contracts
Deploying smart contracts to Flow's networks is the final step in bringing your blockchain application to life. This guide covers everything you need to know to deploy your Cadence contracts to both Flow Testnet and Mainnet, from account creation to contract updates.
What You'll Learn
After completing this guide, you'll be able to:
- Create and fund accounts on Flow Testnet and Mainnet
- Deploy contracts using Flow CLI with proper configuration
- Update existing contracts while preserving their addresses
- Understand the differences between testnet and mainnet deployment
- Follow security best practices for production deployments
Prerequisites
Before deploying contracts, make sure you have:
- Flow CLI installed and configured
- A Flow project with contracts ready for deployment
- Basic understanding of Cadence smart contracts
- Completed testing of your contracts locally
Deployment Workflow
The recommended deployment workflow follows this progression:
- Emulator Deployment - Deploy and test your contracts locally (free, instant)
- Testnet Deployment - Deploy and test your contracts on Flow Testnet (free)
- Mainnet Deployment - Deploy to Flow Mainnet once testing is complete (costs FLOW tokens)
- Contract Updates - Update contracts as needed using the update command
This approach ensures your contracts work correctly before committing real resources to mainnet deployment.
Deploy to Emulator
The Flow Emulator is your local development environment where you can deploy and test contracts instantly without any network costs or delays. This is the first step in your deployment journey.
Start the Emulator
First, start the Flow Emulator. In a second terminal:
_10flow emulator start
Create an Emulator Account
Create a local account for testing:
_10flow accounts create --network emulator
When prompted:
- Account name: Enter
emulator-account
- Select
emulator
as the network when prompted
This creates a new account on the emulator and adds it to your flow.json
configuration.
Configure Emulator Deployment
Update your flow.json
to include emulator deployment configuration:
_10flow config add deployment
Follow the prompts:
- Network:
emulator
- Account:
emulator-account
- Contract:
YourContract
- Deploy more contracts:
no
(oryes
if you have multiple contracts)
Your flow.json
will now include an emulator deployment section:
_10{_10 "deployments": {_10 "emulator": {_10 "emulator-account": ["YourContract"]_10 }_10 }_10}
Deploy Contract to Emulator
Deploy your contract to the local emulator:
_10flow project deploy --network emulator
You cannot deploy the same contract to multiple accounts on the same network with one deployment command. If you attempt to do so, you will see:
❌ Command Error: the same contract cannot be deployed to multiple accounts on the same network
Edit flow.json
to remove the duplicate.
You will see output similar to:
_10Deploying 1 contracts for accounts: emulator-account_10_10YourContract -> 0xf8d6e0586b0a20c7 (contract deployed successfully)_10_10🎉 All contracts deployed successfully
Test Your Emulator Deployment
Verify your contract works by running scripts and transactions:
_10# Run a script to read contract state_10flow scripts execute cadence/scripts/YourScript.cdc --network emulator_10_10# Send a transaction to interact with your contract_10flow transactions send cadence/transactions/YourTransaction.cdc --network emulator --signer emulator-account
The emulator provides instant feedback and is perfect for rapid development and testing. All transactions are free and execute immediately.
Deploy to Testnet
For a more complete quickstart, visit the Getting Started guide.
- You should test your contracts, transactions and scripts on Testnet, have strong smart contract test coverage and follow the additional guidelines set out here: Smart Contract Testing Guidelines.
- Use
flow init
to Create a Project if you need one to practice deployment with.
Create a Testnet Account
First, you'll need a testnet account to deploy your contracts. Create one with:
_10flow accounts create --network testnet
For security reasons, Flow Cadence does not allow accounts to have the same address on testnet, mainnet, and/or the emulator.
When prompted:
- Account name: Enter
testnet-account
- Select
testnet
as the network when prompted
This creates a new account on testnet and adds it to your flow.json
configuration. It also saves the private key for the new account in <account-name>.pkey
and uses this file to import the key because flow.json
will be visible in the repo.
As with any other blockchain network, anyone with access to the private key for an account can access that account at any time without you knowing.
Fund Your Testnet Account
To deploy contracts and send transactions on testnet, you need FLOW tokens. Flow provides a faucet service to get free testnet tokens.
_10flow accounts fund testnet-account
This will open the faucet in your browser. You can also navigate there manually.
- Visit the Testnet Faucet
- Enter your testnet account address
- Complete any required verification (captcha, etc.)
- Request tokens (you'll receive 100000 testnet FLOW tokens)
Check your account balance:
_10flow accounts list
You will see your account details with a balance of FLOW tokens.
Configure Testnet Deployment
Update your flow.json
to include testnet deployment configuration:
_10flow config add deployment
Follow the prompts:
- Network:
testnet
- Account:
testnet-account
- Contract:
YourContract
- Deploy more contracts:
no
(oryes
if you have multiple contracts)
Your flow.json
will now include a testnet deployment section:
_10{_10 "deployments": {_10 "testnet": {_10 "testnet-account": ["YourContract"]_10 }_10 }_10}
Deploy Contract to Testnet
Deploy your contract to the public testnet:
_10flow project deploy --network testnet
You will see output similar to:
_10Deploying 1 contracts for accounts: testnet-account_10_10YourContract -> 0x9942a81bc6c3c5b7 (contract deployed successfully)_10_10🎉 All contracts deployed successfully
Deploy to Mainnet
Once you've successfully tested your contracts on testnet, you can deploy to mainnet. You'll need a mainnet account with real FLOW tokens.
Create a Mainnet Account
For mainnet, you'll need to acquire FLOW tokens through exchanges or other means, as there's no faucet.
_10flow accounts create --network mainnet
When prompted:
- Account name: Enter
mainnet-account
- Select "Mainnet" Network
Acquire FLOW Tokens
You can purchase FLOW tokens from major exchanges. Make sure your mainnet account has sufficient FLOW tokens to cover deployment costs. Flow is a very efficient network, so even 1.0 FLOW is sufficient to deploy large numbers of contracts.
Configure Mainnet Deployment
Add mainnet deployment configuration to your flow.json
:
_10flow config add deployment --network mainnet
Follow the prompts:
- Network:
mainnet
- Account:
mainnet-account
- Contract:
YourContract
- Deploy more contracts:
no
(oryes
if you have multiple contracts)
Your flow.json
should now include mainnet configuration:
_10{_10 "deployments": {_10 "mainnet": {_10 "mainnet-account": ["YourContract"]_10 }_10 }_10}
Deploy to Mainnet
Deploy your contracts to mainnet:
_10flow project deploy --network mainnet
This deployment costs (a relatively small amount of) real FLOW tokens and cannot be undone. You can however redeploy your contracts to update them, or delete them.
You should see output similar to:
_10Deploying 1 contracts for accounts: mainnet-account_10_10YourContract -> 0xABC123DEF456789 (contract deployed successfully)_10_10🎉 All contracts deployed successfully
All your contract deployment addresses are stored in flow.json
. Mainnet, Testnet and local (emulator) are stored as well.
Deploy updated contracts on mainnet
Contracts can be updated and retain the contract address. You can use the Flow CLI contract update command to redeploy an updated version of your contract:
_10flow accounts update-contract ./YourContract.cdc --signer mainnet-account --network mainnet