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.
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.
- 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
- 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")
-
assets: Stores asset information
asset-id: Unique identifier (string-utf8 36)owner: Current owner's principal addressmetadata: Asset description (string-utf8 256)registered-at: Block height when asset was registeredstatus: Current asset status
-
ownership-history: Records all ownership transfers
asset-id+entry-index: Composite key for each transferprevious-owner: Address of previous ownernew-owner: Address of new ownertimestamp: Block height of transfertransaction-hash: Hash of the transfer transaction
-
asset-indices: Tracks transfer count per asset
asset-id: Asset identifiercurrent-index: Number of transfers for this 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 registeredERR-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 (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 transfernew-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 existERR-NOT-OWNER: Caller is not the current ownerERR-INVALID-PARAM: Invalid asset ID
Example:
(contract-call? .property-registry transfer-ownership "asset-001" 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)(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 (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 (asset-id (string-utf8 36)))Returns the current status of an asset.
Returns: (ok (string-ascii 6)) with the status, or ERR-INVALID-ASSET
- 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
- Real estate ownership tracking
- Vehicle title management
- Intellectual property rights
- Equipment and machinery registration
- Art and collectibles provenance
- Supply chain asset tracking
Deploy this contract to the Stacks blockchain using Clarinet or the Stacks CLI:
clarinet deployTest the contract locally using Clarinet:
clarinet test
clarinet check