A secure, feature-rich Clarity smart contract for creating programmable Bitcoin vaults on Stacks blockchain with time-locks, multi-signature support, and configurable withdrawal limits.
This smart contract enables users to create secure vaults for storing STX tokens with advanced security features including time-locked withdrawals, daily spending limits, multi-signature approval mechanisms, and guardian-based access control.
- Time-Lock Protection: Set unlock dates to prevent premature withdrawals
- Daily Withdrawal Limits: Automatic spending caps that reset every ~144 blocks (~24 hours)
- Multi-Signature Support: Require multiple approvals for withdrawals
- Guardian System: Add trusted parties to co-manage vault access
- Emergency Mode: Global freeze capability for security incidents
- Unlimited Vaults: Create up to 50 vaults per user
- Flexible Configuration: Update time-locks and limits after creation
- Active/Inactive Toggle: Pause vault operations without destroying the vault
- Balance Tracking: Real-time balance and withdrawal monitoring
- Propose: Owner or guardian proposes a withdrawal
- Approve: Required number of guardians approve the proposal
- Execute: Once threshold met, withdrawal executes automatically
(create-vault (timelock-blocks uint) (daily-limit uint) (required-sigs uint))Creates a new vault with specified parameters.
- timelock-blocks: Number of blocks before vault unlocks
- daily-limit: Maximum STX withdrawable per day
- required-sigs: Number of signatures needed for multi-sig withdrawals
(deposit (vault-id uint) (amount uint))Deposits STX into a vault. Anyone can deposit into any active vault.
(withdraw (vault-id uint) (amount uint))Withdraws STX from vault (subject to time-lock, daily limits, and owner verification).
(add-guardian (vault-id uint) (guardian principal))Adds a trusted guardian to the vault. Only vault owner can add guardians.
(remove-guardian (vault-id uint) (guardian principal))Removes a guardian from the vault.
(propose-withdrawal (vault-id uint) (withdrawal-id uint) (amount uint) (recipient principal))Creates a withdrawal proposal requiring guardian approval.
(approve-withdrawal (vault-id uint) (withdrawal-id uint))Guardian approves a pending withdrawal proposal.
(execute-withdrawal (vault-id uint) (withdrawal-id uint))Executes approved withdrawal once signature threshold is met.
(update-timelock (vault-id uint) (new-timelock uint))Updates the vault's time-lock (must be future block height).
(update-daily-limit (vault-id uint) (new-limit uint))Changes the daily withdrawal limit.
(toggle-vault-status (vault-id uint))Activates or deactivates the vault.
Returns complete vault information including balance, time-lock, limits, and settings.
Returns current vault balance.
Lists all vault IDs owned by a user.
Checks if vault has passed its time-lock period.
Returns how much can still be withdrawn today.
Returns details of a pending multi-sig withdrawal.
Checks if emergency mode is active.
| Code | Error | Description |
|---|---|---|
| u100 | err-owner-only |
Action requires contract owner |
| u101 | err-not-authorized |
Caller lacks permission |
| u102 | err-vault-locked |
Vault is locked or inactive |
| u103 | err-insufficient-balance |
Not enough funds in vault |
| u104 | err-invalid-amount |
Amount must be greater than 0 |
| u105 | err-vault-exists |
Vault limit reached |
| u106 | err-vault-not-found |
Vault ID doesn't exist |
| u107 | err-withdrawal-limit |
Daily limit exceeded |
| u108 | err-cooldown-active |
Cooldown period active |
| u109 | err-invalid-timelock |
Invalid time-lock value |
| u110 | err-guardian-exists |
Guardian already added |
| u111 | err-not-guardian |
Caller is not a guardian |
Create a vault with a 1-year time-lock to prevent impulsive spending:
(create-vault u52560 u1000000 u1) ;; ~1 year, 1M STX daily limitMulti-signature vault requiring 3 of 5 executives to approve withdrawals:
(create-vault u144 u5000000 u3) ;; 1 day unlock, 5M daily limit, 3 sigs requiredTime-locked vault with family members as guardians:
(create-vault u262800 u10000000 u2) ;; ~5 years, 10M limit, 2 family approvalsShort-term vault with strict daily limits for disciplined investing:
(create-vault u144 u100000 u1) ;; 1 day unlock, 100K daily limit- Time-Lock Immutability: Once set, time-locks can only be extended, not shortened
- Daily Limit Reset: Limits reset automatically every ~144 blocks
- Emergency Mode: Contract owner can freeze all vaults in case of security threat
- No Storage APIs: Contract uses in-memory state only (no localStorage/sessionStorage)
- Guardian Trust: Choose guardians carefully as they have withdrawal proposal powers
- Deploy contract to Stacks blockchain
- Initialize with desired global parameters
- Users create individual vaults with custom settings
- Add guardians for multi-sig protection
- Deposit funds and configure time-locks