Time Locks & Access Control
Beginner
30 minutes

Block-Height Time Lock (Timelocked Payments)

Lock funds until a specific block height for scheduled payments

Problem

You need to lock funds until a future date for vesting, escrow, or scheduled payments.

Solution

ErgoScript can check the current block HEIGHT against a target. Funds remain locked until the blockchain reaches the specified height (~2 min/block on Ergo).

How It Works

  1. 1Calculate target block height: current + (days * 720) for approximate timing
  2. 2Ergo averages ~2 minutes per block (720 blocks/day)
  3. 3Contract checks HEIGHT >= targetHeight before allowing spend
  4. 4Before target: funds are locked, no spending possible
  5. 5After target: only the designated beneficiary can claim

Code Examples

{
  // Lock until block height 1,500,000
  val unlockHeight = 1500000
  val beneficiary = PK("9f...")  // Beneficiary public key
  
  // Can only spend after unlock height
  HEIGHT >= unlockHeight && proveDlog(beneficiary)
}

Simplest time lock. Funds are locked until the specified block height, then only the beneficiary can claim.

Use Cases

  • Team token vesting schedules
  • Scheduled salary payments
  • Escrow with timeout refunds
  • Inheritance and succession planning
  • Delayed governance execution
  • Bond maturity contracts

Security Considerations

  • !Block times can vary slightly - don't rely on exact timing
  • !Consider adding emergency unlock with multi-sig
  • !Test unlock conditions thoroughly on testnet
  • !Keep fee reserves for future unlock transactions

Resources

Fee Considerations

Standard transaction fees. Reserve ~0.01 ERG for future unlock transaction.

Level Up Your ErgoScript Skills

Get notified about new patterns, tutorials, and developer resources.

Follow for daily updates