💡 Inspiration

The genesis of InvoiceChain Pro lies in a common frustration faced by SMEs and freelancers: the Cash Flow Gap. Traditional B2B invoicing is plagued by:

  • Opaque Approval Processes: "Where is my invoice?" is a question asked too often.
  • Delayed Settlements: Even after approval, bank transfers can take days.
  • Lack of Trust: Relying on handshake agreements or email threads for payment promises.

We realized that Blockchain is the perfect settlement layer for B2B finance—not just for the currency, but for the process. By encoding the "rules of engagement" into smart contracts, we can turn a bureaucratic nightmare into a deterministic, automated workflow.

🛠 What it does

InvoiceChain Pro is a comprehensive decentralized application (dApp) that bridges the gap between traditional invoicing and DeFi payment rails. It allows businesses to:

  1. Generate On-Chain Invoices: Vendors mint invoices as immutable records on Ethereum.
  2. ** Automated Approval Chains**: Invoices automatically route through a governance logic based on their value.
    • Small invoices (< 1,000 MNEE) are auto-approved.
    • Large invoices (> 10,000 MNEE) require multi-sig sign-off from treasury wallets.
  3. Smart Escrow Settlement: Once an invoice is created, the Buyer locks funds into a SmartEscrow contract. These funds are programmatically released only when the approval conditions are met—guaranteeing payment for the Vendor and delivery for the Buyer.
  4. Instant Tax Compliance: The system automatically calculates a 1% TDS (Tax Deducted at Source) and diverts it to a designated tax wallet in real-time, simplifying compliance.

⚙️ How we built it

We adopted a Feature-First Architecture, ensuring every layer of the stack contributed to a seamless user experience.

1. Smart Contracts (The Trust Layer)

Built with Solidity and Hardhat, our contracts are the backbone of the system.

  • InvoiceManager.sol: Acts as the central registry. It handles invoice creation validation and emits events for the indexer.
  • SmartEscrow.sol: A secure vault implementation. We used the Checks-Effects-Interactions pattern to prevent reentrancy attacks during fund release.
  • ApprovalWorkflow.sol: This is the "brain". It stores configurable thresholds that dictate how many signatures an invoice needs.

Mathematical Model for Dynamic Thresholds: We defined a piecewise function for approvals $A(v)$ based on invoice value $v$:

$$ A(v) = \begin{cases} 0 & \text{if } v < 1,000 \text{ MNEE} \quad (\text{Auto-Approve}) \ 1 & \text{if } 1,000 \le v < 10,000 \text{ MNEE} \ \min(3, \lfloor \frac{v}{10,000} \rfloor + 1) & \text{if } v \ge 10,000 \text{ MNEE} \end{cases} $$

2. Frontend (The User Interface)

We built a responsive, dark-mode dashboard using Next.js 14 (App Router).

  • State Management: Used TanStack Query to handle async blockchain state and caching.
  • Wallet Integration: Leveraged Wagmi v2 and RainbowKit for a polished "Connect Wallet" experience that supports ENS name resolution.
  • Real-time Feedback: Implemented optimistic UI updates so users see their actions reflected instantly while the transaction confirms in the background.

3. Backend (The Indexing Layer)

To ensure the dashboard loads instantly (without waiting for slow RPC calls), we built a lightweight Express.js indexer.

  • Listens for InvoiceCreated and EscrowReleased events.
  • Decodes hexadecimal event logs and stores metadata in a high-performance in-memory cache.
  • Serves rich data analytics endpoint /api/analytics for the dashboard charts.

🚧 Challenges we ran into

  • Handling BigInt Serialization: JavaScript's JSON.stringify fails with BigInt (common in Ethereum's 18 decimal precision). We had to implement custom serializers to bridge the gap between the Solidity uint256 and the frontend TypeScript interfaces.
  • Race Conditions in Approval: We faced an issue where two approvals submitted simultaneously for the same invoice caused a transaction failure. We solved this by using optimistic locking in the contract logic.
  • Gas Optimization: Storing full invoice details (line items, descriptions) on-chain was too expensive. We optimized this by storing a Content Hash (IPFS CID) on-chain, while keeping the heavy text data off-chain.

🏅 Accomplishments that we're proud of

  • Zero-Knowledge Privacy (Planned): We laid the groundwork to obscure the exact invoice amounts using ZK proofs in the future.
  • Seamless Onboarding: The "Try Demo" mode allows non-crypto users to experience the flow without needing a wallet, vastly increasing our potential user base.
  • Robust Security: Achieved 100% test coverage on critical financial functions (releaseFunds, refund) in our Hardhat test suite.

🧠 What we learned

  • The "Last Mile" Problem: Getting crypto payments is easy; getting them linked to a specific business outcome (like an approved PDF invoice) is hard.
  • Standards Matter: Strictly adhering to ERC-20 standards for the MNEE token ensured out-of-the-box compatibility with Metamask and other wallets.
  • User Experience acts as Trust: A well-designed UI isn't just pretty; in Web3, it reassures the user that the underlying smart contract interaction is safe.

🚀 What's next for InvoiceChain

  • Cross-Chain Settlement: deploying SmartEscrow on Layer 2 solutions (Arbitrum/Optimism) to reduce gas fees to <$0.01.
  • DAO Governance: Allowing the community to vote on the ApprovalWorkflow thresholds.
  • Fiat On-Ramps: Integrating Stripe API to allow Buyers to pay in USD, which instantly swaps to MNEE MNEE for the escrow lock.

Built With

Share this project:

Updates