Skip to content

chike-smith/PropertyRegistry-Smart-Contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

PropertyRegistry Smart Contract

A Clarity smart contract for managing real-world asset ownership records on the Stacks blockchain. This contract provides secure ownership tracking, transfer validation, and comprehensive history logging for assets.

Overview

PropertyRegistry enables users to register assets, transfer ownership, and maintain an immutable record of all ownership changes. Each asset is identified by a unique ID and includes metadata, ownership information, and a complete transfer history.

Features

  • Asset Registration: Register new assets with unique identifiers and metadata
  • Ownership Transfer: Transfer asset ownership with automatic validation
  • Transfer History: Complete, immutable record of all ownership changes
  • Ownership Verification: Built-in validation to ensure only owners can transfer assets
  • Status Tracking: Monitor asset status and registration details

Contract Structure

Constants

  • Error Codes: ERR-NOT-AUTHORIZED, ERR-INVALID-ASSET, ERR-ASSET-EXISTS, ERR-NOT-OWNER, ERR-INVALID-ACTION, ERR-INVALID-PARAM
  • CONTRACT-OWNER: The address that deployed the contract
  • STATUS-ACTIVE: Default status for registered assets ("active")

Data Maps

  1. assets: Stores asset information

    • asset-id: Unique identifier (string-utf8 36)
    • owner: Current owner's principal address
    • metadata: Asset description (string-utf8 256)
    • registered-at: Block height when asset was registered
    • status: Current asset status
  2. ownership-history: Records all ownership transfers

    • asset-id + entry-index: Composite key for each transfer
    • previous-owner: Address of previous owner
    • new-owner: Address of new owner
    • timestamp: Block height of transfer
    • transaction-hash: Hash of the transfer transaction
  3. asset-indices: Tracks transfer count per asset

    • asset-id: Asset identifier
    • current-index: Number of transfers for this asset

Public Functions

register-asset

(register-asset (asset-id (string-utf8 36)) (metadata (string-utf8 256)))

Registers a new asset with the caller as the initial owner.

Parameters:

  • asset-id: Unique identifier for the asset (must be non-empty, max 36 characters)
  • metadata: Description or details about the asset (must be non-empty, max 256 characters)

Returns: (ok uint) with the transfer record index, or an error

Errors:

  • ERR-ASSET-EXISTS: Asset ID already registered
  • ERR-INVALID-PARAM: Invalid asset ID or metadata (empty strings)

Example:

(contract-call? .property-registry register-asset "asset-001" "123 Main St, Apartment Building")

transfer-ownership

(transfer-ownership (asset-id (string-utf8 36)) (new-owner principal))

Transfers asset ownership to a new address. Only the current owner can initiate transfers.

Parameters:

  • asset-id: Identifier of the asset to transfer
  • new-owner: Principal address of the new owner

Returns: (ok uint) with the transfer record index, or an error

Errors:

  • ERR-INVALID-ASSET: Asset does not exist
  • ERR-NOT-OWNER: Caller is not the current owner
  • ERR-INVALID-PARAM: Invalid asset ID

Example:

(contract-call? .property-registry transfer-ownership "asset-001" 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)

Read-Only Functions

get-asset-owner

(get-asset-owner (asset-id (string-utf8 36)))

Returns the current owner of an asset.

Returns: (ok principal) with the owner's address, or ERR-INVALID-ASSET

get-transfer-history

(get-transfer-history (asset-id (string-utf8 36)))

Retrieves transfer history summary for an asset.

Returns:

(ok {
    asset-id: (string-utf8 36),
    total-transfers: uint,
    latest-transfer: (optional transfer-record)
})

get-asset-status

(get-asset-status (asset-id (string-utf8 36)))

Returns the current status of an asset.

Returns: (ok (string-ascii 6)) with the status, or ERR-INVALID-ASSET

Security Features

  • Input Validation: All inputs are validated before processing
  • Ownership Verification: Only current owners can transfer their assets
  • Duplicate Prevention: Prevents registering assets with existing IDs
  • Immutable History: All transfers are permanently recorded on-chain

Use Cases

  • Real estate ownership tracking
  • Vehicle title management
  • Intellectual property rights
  • Equipment and machinery registration
  • Art and collectibles provenance
  • Supply chain asset tracking

Deployment

Deploy this contract to the Stacks blockchain using Clarinet or the Stacks CLI:

clarinet deploy

Testing

Test the contract locally using Clarinet:

clarinet test
clarinet check

About

PropertyRegistry is a Clarity smart contract designed to manage real-world asset ownership records on the Stacks blockchain. It provides a decentralized, tamper-proof system for registering assets, transferring ownership, and maintaining complete historical records of all ownership changes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors