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.yaml

Example output structure:

deployments/default.devnet-plan.yaml
---
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

Field
Description

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 requirements

  • Network 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

Prerequisites:

  • Request testnet STX from the faucet

  • Configure your account in settings/Testnet.toml

  • Validate contracts with clarinet check

Generate a deployment plan with cost estimation:

Deploy to testnet:

Mainnet

1

Finish thorough testing on testnet

2

Audit contracts for security

3

Ensure sufficient STX for fees

4

Back up deployment keys securely

5

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:

Transaction type
Description

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.

Manual edits

When Clarinet prompts to overwrite your plan, answer no to keep custom changes.

Example contract initialization batch:

Common issues

Insufficient STX balance

Error: “Insufficient STX balance for deployment”

Solutions:

1

Request testnet STX from the faucet

2

Reduce the fee rate with --low-cost

3

Check your balance:

Contract already exists

Error: “Contract token already deployed at this address”

Solutions:

1

Use a different contract name

2

Deploy from another address

3

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.so

  • Your 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?