Trustless micropayment channels for pay-as-you-go DeFi data using Hashchain Protocol and 1inch API.
Micropay Agents is a TypeScript framework enabling secure, off-chain micropayment channels between a client and merchant, anchored by Ethereum smart contracts through the Hashchain Protocol. It facilitates incremental, gasless and trustless payments for each data item or API call using cryptographic hashchains, enabling true pay-as-you-go billing.
This system integrates with real-time DeFi portfolio data from the 1inch Portfolio API, allowing users to pay per requested Ethereum address portfolio dynamically. By combining off-chain payment efficiency with on-chain settlement security, Micropay Agents supports granular metering for APIs, DeFi dashboards, autonomous AI agent transactions, and IoT data monetization.
We built Micropay Agents using TypeScript and Express.js for backend APIs, and Hashchain Protocol sdk with ethers.js to interact with Ethereum smart contracts. The core payment logic leverages the Hashchain Protocol, where clients generate cryptographic hashchains whose preimages serve as incremental micropayment tokens, validated off-chain by the merchant. This design minimizes on-chain transaction costs while maintaining trustless guarantees.
The merchant agent listens for on-chain ChannelCreated events to track active payment channels and validates payment tokens against stored channel state. After payments complete, the merchant redeems the accumulated funds on-chain via the Hashchain Protocol (MuPay) smart contract.
To demonstrate a real-world DeFi use case, we integrated the 1inch Portfolio API, allowing clients to request on-demand, detailed DeFi portfolio data for arbitrary Ethereum addresses and pay securely per query with hashchain tokens. This integration highlights micropayments applied to live DeFi data APIs, aligning with ETHGlobal Unite DeFi Hackathon goals.
We implemented a full payment lifecycle including channel negotiation, creation, incremental off-chain payments, data delivery, and on-chain redemption. We accounted for asynchronous blockchain event propagation by implementing client-side wait logic before starting payments. The system also manages state carefully with address normalization to prevent key mismatches, ensuring robustness.
The project benefits from the partnership with 1inch, leveraging their Portfolio API to obtain live, aggregated DeFi data. This not only enriches the use case but illustrates seamless integration of third-party DeFi APIs into a micropayment architecture, unlocking new monetization patterns.