AHADI Docs
AHADI (Swahili for "Promise") is a trustless escrow protocol on the Polygon blockchain. It eliminates the need for intermediaries when transacting with unknown parties — your funds are held by immutable code, not a person.
constants/index.ts before mainnet deployment.How It Works
Every deal goes through the same trustless lifecycle, enforced on-chain.
Contract Overview
The AhadiEscrow.sol contract is written in Solidity 0.8.19 and uses the OpenZeppelin ReentrancyGuard and SafeERC20 libraries. It supports native ERC-20 USDT deposits with time-locked expiry.
Deal State Machine
Deal Struct
struct Deal {
uint256 id;
address buyer;
address seller;
uint256 amount; // in USDT (6 decimals)
bool isCompleted;
bool isDisputed;
uint256 createdAt;
uint256 expiryTime; // unix timestamp
}Functions Reference
All state-changing functions require a connected wallet. View functions can be called without gas.
User Functions
createDeal(address _seller, uint256 _amount, uint256 _timeoutSeconds) → uint256 dealIdLocks USDT from the buyer into the contract vault and creates a new deal. Returns the new deal ID. The buyer must approve the escrow contract to spend at least _amount USDT first.
releaseFunds(uint256 _dealId)Marks the deal as completed and transfers USDT to the seller. Can only be called by the buyer of the specified deal while the deal is still active.
refundBuyer(uint256 _dealId)Allows the seller to voluntarily cancel an active deal and refund the buyer. Useful when goods cannot be delivered.
refundTimedOutDeal(uint256 _dealId)Returns USDT to the buyer if the deal's expiryTime has passed and the deal is still active. No admin approval needed.
raiseDispute(uint256 _dealId)Flags a deal as disputed, freezing it until the AHADI admin resolves it. Either party can raise a dispute on an active deal.
Admin Functions
resolveDispute(uint256 _dealId, address _winner)Transfers the locked USDT to the winning party (_winner must be buyer or seller). Only callable by the contract owner.
updateFee(uint256 _newFee)Updates the platform fee in basis points (e.g. 100 = 1%). Currently set to 0 — the platform charges no fees.
View Functions
getDeal(uint256 _dealId) → DealReturns the full Deal struct for a given deal ID. Use this to check the status, parties, amount, and expiry of any deal.
getContractStats() → (totalDeals, locked, balance, excess)Returns aggregate stats: total deals created, total USDT locked, current USDT balance, and any excess (unclaimed).
Error Codes
The contract uses custom errors for gas-efficient reverts. When a transaction fails, decode the revert reason to get the exact error name.
| Error |
|---|
| InvalidDealID |
| Unauthorized |
| DealClosed |
| DealDisputed |
| DealNotDisputed |
| DealNotTimedOut |
| InvalidState |
| InvalidAmount |
| InvalidAddress |
| SelfDeal |
| TimeoutRange |
For Sellers
Sellers create deals by generating payment links and sharing them with buyers. No coding required.
- 1Connect your walletClick 'Sign In' on the landing page and connect with your preferred wallet (MetaMask, Coinbase Wallet, etc.). Make sure you're on the Polygon Mainnet network.
- 2Navigate to the Seller tabIn the Dashboard, select the Seller tab and click 'Generate Payment Request'.
- 3Fill in deal detailsEnter the item name, the price in USDT, and the delivery timeout (in hours). The minimum timeout is 1 hour; maximum is 90 days.
- 4Copy and share the linkAHADI generates a unique URL that encodes all deal parameters. Share this link with your buyer via any channel — Instagram DM, WhatsApp, email, etc.
- 5Wait for the buyer to lock fundsOnce the buyer locks USDT, you'll see the deal appear in 'My Deals' with status Active. You'll receive an on-chain event.
- 6Deliver and get paidDeliver the goods. When the buyer releases funds, the USDT arrives in your wallet instantly.
For Buyers
When you receive a payment link from a seller, here's what happens step by step.
- 1Open the payment linkThe seller's link takes you to the AHADI deal page with all details pre-filled: seller address, item name, price, and timeout.
- 2Connect your walletClick 'Sign In'. Your wallet must hold at least the deal amount in USDT (Polygon Mainnet) plus a small amount of MATIC for gas.
- 3Approve USDT spendingAHADI will ask you to sign two transactions: (1) Approve the escrow contract to spend your USDT, (2) Call createDeal() to lock the funds.
- 4Receive the goodsThe seller is now incentivised to deliver. Your funds are safe in the contract — they can only go to the seller if you release them, or back to you if you raise a dispute or the timeout expires.
- 5Release funds or disputeInspect the goods. Happy? Click 'Release Funds'. Problem? Click 'Raise Dispute' and submit your evidence.
Disputes & Resolution
Either party can raise a dispute while the deal is active. Once raised, the deal is frozen — neither party can release or refund until an admin resolves it.
- Goods not delivered before timeout
- Item significantly differs from description
- Counterfeit or damaged goods received
- Seller refuses to communicate
- Chat screenshots (WhatsApp, Instagram DMs)
- Photos or video of delivered item
- Tracking numbers / courier receipts
- Transaction receipts or invoices
Submit evidence to support@ahadi.com with your deal ID. The admin will call resolveDispute(dealId, winner) on-chain within 48 hours. In Q4 2026, this manual step will be replaced by Amani AI for sub-$100 disputes.
Architecture
AHADI is a three-layer system: a Solidity smart contract, a React frontend, and a Graph Protocol subgraph for indexing.
Server-rendered React app with client-side wallet hooks. React Three Fiber powers the 3D padlock. Reown AppKit / Wagmi handle all wallet connections and chain interactions.
Single-file escrow contract with ReentrancyGuard protection. Stores deal state in a mapping(uint256 => Deal). All events are emitted for subgraph indexing.
Subgraph listens to DealCreated, FundsReleased, DisputeRaised, and DisputeResolved events and exposes a GraphQL API for the dashboard's deal history queries.
Contract Addresses
| Contract | Network | Address |
|---|---|---|
| AhadiEscrow.sol | Polygon (Mainnet) | 0x7445B80f07ffcC031cecd3FC645878Baa8373819 |
| USDT (Mainnet) | Polygon (Mainnet) | 0xc2132D05D31c914a87C6611C10748AEb04B58e8F |
Subgraph & Indexing
The AHADI subgraph indexes all on-chain events from the escrow contract. Query it via GraphQL to get deal history, stats, and event timelines without scanning the blockchain yourself.
Example Query
{
deals(orderBy: createdAt, orderDirection: desc, first: 10) {
id
buyer
seller
amount
isCompleted
isDisputed
createdAt
expiryTime
}
}