Contract Deployment
Clarinet provides deployment tooling that helps you move from local development to production networks. Whether you're testing on devnet, staging on testnet, or launching on mainnet, Clarinet streamlines the process.
Generating deployment plans
Deployment plans are YAML files that describe how contracts are published or called. Be sure to have a valid 24 word mnemonic seed phrase specified in the target network's .toml file in settings/ and then generate a plan for any network:
$ clarinet deployments generate --testnet --medium-cost
Analyzing contracts...
Calculating deployment costs...
Generating deployment plan
Created file deployments/default.testnet-plan.yamlExample output structure:
---
id: 0
name: Devnet deployment
network: devnet
stacks-node: "http://localhost:20443"
bitcoin-node: "http://devnet:devnet@localhost:18443"
plan:
batches:
- id: 0
transactions:
- contract-publish:
contract-name: counter
expected-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
cost: 6940
path: contracts/counter.clar
anchor-block-only: true
clarity-version: 2
epoch: "2.5"Deployment plan structure
id
Unique identifier for the deployment
name
Human-readable deployment name
network
Target network (devnet, testnet, or mainnet)
stacks-node
RPC endpoint for the Stacks node
bitcoin-node
RPC endpoint for the Bitcoin node
plan.batches
Array of deployment batches
Deployment specifications
Deployment behavior is configured in two places:
Project configuration (
Clarinet.toml) – Clarity versions, dependencies, epoch requirementsNetwork configuration (
settings/<network>.toml) – Account details, balances, endpoints
Example network configuration:
Working with contract requirements
Reference contracts that already exist on-chain—useful for standardized traits.
Adding requirements
Clarinet updates your configuration automatically:
During deployment Clarinet downloads the contract, remaps the principal for devnet, and ensures the requirement is available before your contracts deploy.
Deploying to different networks
Devnet
Devnet deploys contracts automatically when it starts:
To deploy manually against a running devnet:
See local development for more devnet configuration tips.
Testnet
Generate a deployment plan with cost estimation:
Deploy to testnet:
Mainnet
Mainnet checklist
Finish thorough testing on testnet
Audit contracts for security
Ensure sufficient STX for fees
Back up deployment keys securely
Prefer a hardware wallet for deployment
Create a mainnet plan:
Deploy with confirmation:
Cost estimation and optimization
Choose the right fee level for your deployment:
Fee options:
--low-cost– minimize fees, slower confirmation--medium-cost– balanced approach--high-cost– priority inclusion--manual-cost– interactive selection
Analyze costs before deploying:
Advanced deployment configurations
Multi-batch deployments
Deploy complex systems with batches:
Batches guarantee that dependencies deploy first, allow parallel transactions within a batch, and run batches sequentially.
Transaction types
Deployment plans support different transaction types:
Contract operations
Publish or call contracts, specifying sender, cost, and source path
Asset transfers
Transfer STX or BTC by setting sender, recipient, and amounts
Contract operations
Asset transfers
Manual customization
You can edit deployment plans for complex scenarios.
Example contract initialization batch:
Common issues
Insufficient STX balance
Error: “Insufficient STX balance for deployment”
Solutions:
Request testnet STX from the faucet
Reduce the fee rate with --low-cost
Check your balance:
Contract already exists
Error: “Contract token already deployed at this address”
Solutions:
Use a different contract name
Deploy from another address
On testnet, switch to a fresh account
Network connection failures
Error: “Failed to connect to testnet node”
Check your network settings:
Alternative endpoints:
Hiro:
https://api.testnet.hiro.soYour own node
Debug the connection:
Invalid deployment plan
Common YAML errors
Incorrect indentation
Missing required fields
Invalid contract paths
Validate and regenerate as needed:
Last updated
Was this helpful?
