Guide deployment of Clarity contracts to testnet or mainnet with pre-flight checks and safety prompts. Use when the user wants to deploy contracts to a live network.
This skill guides safe deployment of Clarity contracts to Stacks testnet or mainnet.
Run these checks before any deployment:
1.1 Contract Compilation:
clarinet check
If this fails, stop and help fix errors first.
1.2 Test Suite:
npm run test 2>&1 | tail -20
If tests fail, strongly recommend fixing before deployment.
1.3 Test Coverage (Recommended):
npm run test:coverage 2>&1 | grep -A 5 "Coverage summary" || echo "No coverage script found"
Tell the user: "Pre-flight check results:
[If any fail]: I recommend fixing these issues before deploying. [If all pass]: Ready for deployment. Which network?"
Ask the user: "Which network would you like to deploy to?
Testnet (Recommended for first deployment)
Mainnet
Which would you prefer?"
Generate deployment plan:
clarinet deployments generate --testnet
This creates deployments/default.testnet-plan.yaml.
Show the deployment plan:
cat deployments/default.testnet-plan.yaml
Explain what will be deployed and estimated costs.
Check STX balance:
Tell the user: "Before deploying, ensure your testnet account has STX for transaction fees.
Get free testnet STX:
Do you have sufficient testnet STX? Let me know when ready to deploy."
Apply deployment:
clarinet deployments apply -p deployments/default.testnet-plan.yaml
Post-deployment: Show the deployed contract addresses and explorer links: "Deployment complete!
Your contracts are now live on testnet:
contract-name: [address]
Explorer: https://explorer.hiro.so/txid/[txid]?chain=testnetNext steps:
IMPORTANT: Extra safety for mainnet
3B.1 Require testnet deployment first:
Ask: "Have you successfully deployed and tested these contracts on testnet?
Mainnet deployment is permanent. I strongly recommend:
If you haven't deployed to testnet yet, would you like to do that first?"
If user hasn't tested on testnet, encourage them to do so first.
3B.2 Security Checklist:
Present this checklist to the user: "Mainnet Deployment Security Checklist
Please confirm each item:
For professional security review, consider:
/stacks:expert-advice for best practices checkType 'confirmed' when you've reviewed this checklist, or ask questions about any item."
3B.3 Generate mainnet plan:
clarinet deployments generate --mainnet
Show deployment plan and cost estimate:
cat deployments/default.mainnet-plan.yaml
3B.4 Final confirmation:
"FINAL CONFIRMATION
You are about to deploy to MAINNET. This action:
Contracts to deploy: [List contracts from plan]
Estimated cost: [X STX]
Type 'deploy to mainnet' to proceed, or 'cancel' to abort."
3B.5 Apply mainnet deployment:
Only proceed if user explicitly confirms.
clarinet deployments apply -p deployments/default.mainnet-plan.yaml
For priority deployment (higher fees, faster confirmation):
clarinet deployments apply -p deployments/default.mainnet-plan.yaml --high-cost
Post-deployment: "Mainnet deployment complete!
Your contracts are now live:
contract-name: [address]
Explorer: https://explorer.hiro.so/txid/[txid]?chain=mainnetIMPORTANT REMINDERS:
Congratulations on your mainnet launch!"
Error: Insufficient balance "Your account doesn't have enough STX for deployment fees.
For testnet: Get free STX at https://explorer.hiro.so/sandbox/faucet?chain=testnet For mainnet: Transfer STX from an exchange or wallet"
Error: Contract already exists "A contract with this name already exists at this address.
Options:
Error: Transaction timeout "The transaction is taking longer than expected.
Check status: https://explorer.hiro.so/txid/[txid]?chain=[network]
The transaction may still succeed. Wait and check the explorer before retrying."
Error: Nonce mismatch "There's a nonce mismatch, likely from a pending transaction.
Wait for pending transactions to confirm, then retry deployment."
--high-cost flag for priority mainnet deploymentsclarinet check) before deployment