This project provides a robust and feature-rich smart contract for managing real estate transactions on the Stacks blockchain using Clarity. The contract automates the processes of property listing, buying, selling, and dispute resolution, reducing the need for intermediaries and ensuring transparency and security in real estate transactions.
-
Property Listing and Metadata:
- Register properties as non-fungible tokens (NFTs) with unique asset IDs.
- Include property details like cost and listing duration.
-
Automated Transactions:
- Automate the buying and selling of properties.
- Use an escrow mechanism to hold funds and transfer ownership once conditions are met.
-
Multi-Signature Approval:
- Require multiple approvers to validate high-value transactions.
- Ensure security and consensus before completing a property sale.
-
Dynamic Pricing and Listing Expiration:
- Allow property owners to update property prices.
- Automatically cancel property listings after the expiration period.
-
Dispute Resolution:
- Reset transactions in case of disputes or errors, safeguarding both buyers and sellers.
- Stacks Blockchain Network: A Stacks node or access to a network like the Stacks Testnet or Mainnet.
- Clarity Smart Contract Development Tools: Install Clarinet for local development and testing.
- Familiarity with Clarity Language: Basic knowledge of the Clarity language and the Stacks ecosystem.
The smart contract consists of the following key components:
-
Variables:
property-owner: Stores the address of the property owner.potential-buyer: Optionally stores the address of a potential buyer.property-cost: The cost of the property in microSTX.transaction-complete: A boolean flag indicating if the property has been sold.property-asset-id: The unique ID representing the property NFT.listing-expiration: Expiration time of the property listing in blocks.multi-signature-approvers: A list of principals who can approve the transaction.approvers-count: The number of approvals received for the transaction.
-
NFT Definition:
real-estate-nft: Represents the property as a non-fungible token.
-
Core Functions:
register-property: Registers a property with a cost, asset ID, and expiration duration.submit-offer: Allows a buyer to express interest in the property.add-approver: Adds a multi-signature approver for the transaction.approve-transaction: Approves the transaction from an approver's side.complete-transaction: Finalizes the sale, transferring ownership and funds.withdraw-offer: Allows the buyer to withdraw their offer.update-property-cost: Updates the cost of the property.cancel-listing-if-expired: Cancels the property listing if the expiration time has passed.reset-transaction: Resets the transaction in case of disputes.
-
Events:
property-listed: Logs details when a property is listed.transaction-completed: Logs details when a transaction is successfully completed.
-
Install Clarinet:
- Follow the instructions on the Clarinet GitHub page to install the Clarinet tool.
-
Clone the Repository:
- Clone this repository to your local machine:
git clone https://github.com/your-username/real-estate-smart-contract.git cd real-estate-smart-contract
- Clone this repository to your local machine:
-
Compile the Contract:
- Use Clarinet to compile the smart contract:
clarinet check
- Use Clarinet to compile the smart contract:
-
Run Tests:
- Ensure the contract logic is working correctly by running the tests:
clarinet test
- Ensure the contract logic is working correctly by running the tests:
-
Deploy the Contract:
- Deploy the contract to the desired network (Testnet or Mainnet):
clarinet deploy --network testnet
- Deploy the contract to the desired network (Testnet or Mainnet):
-
Interact with the Contract:
- Use the Clarinet console or Stacks wallet to interact with the contract functions.
(register-property cost asset-id duration)- cost: The cost of the property in microSTX.
- asset-id: The unique ID for the property.
- duration: The number of blocks for which the listing is valid.
(submit-offer)- The potential buyer submits an offer for the property.
(complete-transaction)- Finalizes the sale, transferring ownership and funds, provided that the transaction has the necessary approvals.
(update-property-cost new-cost)- new-cost: The updated cost of the property in microSTX.
(cancel-listing-if-expired)- Cancels the property listing if the listing has expired.
(reset-transaction)- Resets the transaction state, allowing a fresh start in case of disputes.
u100: Unauthorized property registration.u101: Property already sold or inactive.u102: An existing offer is already submitted.u103: Property transaction already completed.u104: No potential buyer available.u105: Only the potential buyer can call this function.u106: Property transaction already completed.u107: Invalid potential buyer.u108: Only the potential buyer can call this function.u109: Property transaction already completed.u110: Listing expired.u111: Only the property owner can add approvers.u112: Maximum number of approvers reached.u113: Caller is not an approver.u114: Insufficient approvals.u115: Only the property owner can update cost.u116: Cannot update cost of a sold property.u117: Property transaction already completed.u118: Listing not yet expired.u119: Only the property owner can reset the transaction.
Contributions to this project are welcome. If you have suggestions for new features, optimizations, or bug fixes, please submit a pull request or open an issue on the GitHub repository.
- Stacks Blockchain for providing a powerful platform to build decentralized applications.
- Clarity Language for enabling predictable and secure smart contracts.
- Community contributors and developers for their valuable feedback and support.
This README provides a comprehensive overview of the project, instructions for setup and usage, as well as details on the contract's functionality and error handling. If you have any questions or need further assistance, feel free to reach out.