Skip to content

This Clarity smart contract implements a sophisticated escrow system for the Stacks blockchain that enables secure, conditional payments between parties. The contract acts as a trustless intermediary, holding STX tokens until predefined conditions are cryptographically verified through SHA256 hash matching.

Notifications You must be signed in to change notification settings

akorede-ajibs/Conditional-Payment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Conditional Payment Smart Contract

A robust escrow system built on the Stacks blockchain using Clarity that enables secure conditional payments between parties with built-in dispute resolution.

Overview

This smart contract implements a trustless escrow service where payments are held until predefined conditions are met. It supports multi-party transactions with optional arbitration and automatic refunds for expired payments.

Key Features

  • Conditional Escrow: Funds locked until cryptographic proof of condition fulfillment
  • Multi-Party Support: Payer, payee, and optional arbiter roles
  • Timeout Protection: Automatic refunds after expiration
  • Dispute Resolution: Arbiter-mediated conflict resolution
  • Fee System: Configurable contract fees (default 0.5%)
  • Security: Comprehensive input validation and access controls

Core Functions

Payment Creation

(create-payment payee amount condition-hash timeout-blocks arbiter)

Creates a new conditional payment with specified terms. Funds are immediately escrowed.

Condition Verification

(verify-condition payment-id proof-data)

Verifies that provided proof matches the original condition hash using SHA256.

Payment Release

(release-payment payment-id)

Releases escrowed funds to payee after conditions are verified. Deducts contract fee.

Refund Processing

(refund-payment payment-id)

Returns funds to payer if payment expired or authorized by arbiter.

Dispute Management

(dispute-payment payment-id)

Flags payment as disputed, requiring arbiter intervention.

Usage Example

  1. Create Payment: Payer creates payment with condition hash and timeout
  2. Verify Condition: Any authorized party submits proof data
  3. Release Payment: Once verified, funds transfer to payee minus fees
  4. Handle Disputes: Arbiter can resolve conflicts or force refunds

Security Features

  • Input Validation: All user inputs validated before processing
  • Access Controls: Only authorized parties can perform actions
  • Reentrancy Protection: State changes before external calls
  • Principal Validation: Prevents invalid or self-referencing addresses

Error Codes

  • u100: Unauthorized access
  • u101: Payment not found
  • u103: Insufficient funds
  • u104: Payment expired
  • u106: Conditions not met
  • u108: Invalid input parameters

Deployment

Deploy using Clarinet or Stacks CLI. Set appropriate contract owner and initial fee structure before mainnet deployment.

This contract provides a secure foundation for conditional payments with comprehensive error handling and dispute resolution mechanisms built for production use.

About

This Clarity smart contract implements a sophisticated escrow system for the Stacks blockchain that enables secure, conditional payments between parties. The contract acts as a trustless intermediary, holding STX tokens until predefined conditions are cryptographically verified through SHA256 hash matching.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published