SlashContract is a decentralized application (dApp) built on the Aptos blockchain ⛓️ using Next.js. It provides a trustless platform for employers and workers to create, manage, and settle work agreements 🤝. By leveraging smart contracts, it ensures that funds are held in escrow 💰 and disbursed automatically according to predefined rules, fostering transparency and security 🔍.
The application currently features a fully functional landing page and an employer dashboard for contract management.
- 📝 On-Chain Contract Creation: Employers can define all aspects of a work agreement—scope, payment, deadline, and penalties—and record them immutably on the Aptos blockchain.
- 🏦 Trustless Escrow: When an employer creates a contract, the payment amount is automatically locked in the smart contract, guaranteeing the availability of funds for the worker upon successful completion.
- 💼 Wallet Integration: Utilizes the Aptos Wallet Adapter for seamless connection with popular Aptos wallets, enabling easy transaction signing and interaction with the dApp.
- 🖥️ Employer Dashboard: A clean and intuitive interface for employers to create new work contracts, monitor the status of ongoing agreements, mark tasks as complete, and settle payments.
- 📱 Responsive UI: Built with Tailwind CSS and shadcn/ui for a modern, responsive user experience across all devices.
This project integrates a modern web2 front-end with a web3 back-end:
- Frontend: Next.js, React, TypeScript
- Blockchain: Aptos 🔗
- Smart Contract Language: Move 📜
- Styling: Tailwind CSS, shadcn/ui 🎨
- Aptos SDKs:
@aptos-labs/ts-sdk,@aptos-labs/wallet-adapter-reactfor client-side interaction with the Aptos network.
The workflow is designed to be straightforward and secure for both parties involved.
- 🔗 Connect Wallet: An employer connects their Aptos wallet to the application.
- ✍️ Create Contract: From the dashboard, the employer fills out a form to create a new contract. This includes specifying the worker's address, a title and description for the job, the payment amount in OCTAS, the number of days for completion, and a penalty amount for missing the deadline.
- 💸 Fund Escrow: Upon submission, the employer signs a transaction that deploys the contract to the blockchain and transfers the specified payment amount from their wallet into the contract's escrow.
- 📋 Manage Contracts: The newly created contract appears on the employer's dashboard with an "In Progress" status. The employer can view all details of their active and completed contracts.
- ✅ Mark Completion: Once the worker has finished the task, the employer can sign a transaction to mark the contract as "Completed".
- 💰 Settle and Pay: The employer triggers the final "Settle & Pay" action. The smart contract automatically executes the
refundorfinefunction, which verifies the completion status and deadline.- If the work was completed on time, the full amount is transferred to the worker's wallet.
- If the deadline was missed, the penalty is subtracted from the total amount, and the remainder is sent to the worker. Any leftover funds (e.g., the penalty amount) are returned to the employer.
The core logic of the dApp is powered by the slash_contract Move module. It defines the data structures and functions for managing work agreements on-chain.
WorkContract: A struct that stores all the essential details of a work agreement, including the employer and worker addresses, payment amount, deadline, penalty, and completion status.WorkContractState: A resource struct stored under the employer's account. It contains tables to manage all contracts (contracts), the funds locked in escrow for each contract (balances), and a list of contract IDs.
These functions are callable by users to create or modify the state of the blockchain.
-
create_contract(employer: &signer, worker: address, amount: u64, ...)- Purpose: Creates and funds a new work contract.
- Action: An
employersigns a transaction to define a new contract. The function validates that thepenaltydoes not exceed theamount. It then withdraws theamountfrom the employer's account and locks it within the smart contract. A newWorkContractis created and stored in the employer'sWorkContractState.
-
mark_completed(account: &signer, employer_addr: address, contract_id: u64)- Purpose: Marks a specific contract as completed.
- Action: This can be called by either the
employeror theworkerassociated with the contract. It sets theis_completedflag of the specifiedcontract_idtotrue.
-
refund_or_fine(employer: &signer, contract_id: u64)- Purpose: Settles a contract by distributing the escrowed funds.
- Action: Only the
employercan call this function. It checks the contract'sis_completedstatus and whether thedeadlinehas passed.- If completed on time, the full
amountis sent to the worker. - If completed late or not completed, the
penaltyis subtracted from theamount, the worker receives the difference, and the penalty amount is returned to the employer. - If the penalty is greater than or equal to the amount, the worker receives nothing, and the full amount is returned to the employer.
- If completed on time, the full
- After payment, the
is_claimedflag is set totrueto prevent double payment.
These are read-only functions that do not require a transaction and can be called to query data from the blockchain.
-
get_contract_by_employer(employer_addr: address, contract_id: u64): WorkContract- Purpose: Retrieves the details of a single work contract by its ID.
- Returns: The
WorkContractstruct for the givencontract_id.
-
get_all_contracts_by_employer(employer_addr: address): vector<WorkContract>- Purpose: Retrieves all contracts created by a specific employer.
- Returns: A vector containing all
WorkContractstructs associated with theemployer_addr.
To run this project locally, you will need Node.js and the Aptos CLI installed.
First, clone the repository to your local machine:
git clone https://github.com/AmanDevelops/slash_contract.git
cd slash_contractInstall the necessary dependencies:
npm installCreate a .env file in the root directory and add the following environment variables. This is necessary for compiling and publishing the smart contract.
NEXT_PUBLIC_MODULE_PUBLISHER_ACCOUNT_ADDRESS=<YOUR-APTOS-ACCOUNT-ADDRESS>
NEXT_PUBLIC_MODULE_ADDRESS=<YOUR-APTOS-ACCOUNT-ADDRESS>
NEXT_PUBLIC_APP_NETWORK=devnet
The smart contract is written in Move and is located in the /contract directory.
Compile the contract: This command compiles the Move code and generates the necessary metadata.
npm run move:compilePublish the contract:
This script publishes the compiled module to the specified network (e.g., devnet). Ensure the account in your .env file has enough funds to cover the transaction fees.
npm run move:publishOnce the contract is on-chain, you can start the Next.js development server.
npm run devOpen your browser and navigate to http://localhost:3000 to see the application in action.
npm run dev: Starts the Next.js development server.npm run build: Builds the application for production.npm run start: Starts a production server.npm run move:compile: Compiles the Move smart contract.npm run move:publish: Publishes the smart contract to the Aptos network.npm run move:test: Runs tests for the smart contract.
This project is licensed under the Apache License 2.0.