@erudite-intelligence/x402-ada
v1.0.0
Published
x402 exact payment scheme implementation for Cardano ADA
Maintainers
Readme
@erudite-intelligence/x402-ada
x402
exactpayment scheme implementation for Cardano ADA.
Part of the EruditePay x402 multi-chain payment infrastructure by Erudite Intelligence LLC.
Overview
This package implements the x402 protocol's exact payment scheme for the Cardano network. It enables HTTP 402-based micropayments using native ADA transfers.
- CAIP-2 Network ID:
cardano:764824073 - Unit: lovelace (1 ADA = 1,000,000 lovelace)
- Signing: Ed25519 via cardano-serialization-lib
- Verification: Blockfrost.io API
Installation
npm install @erudite-intelligence/x402-adaRequires: A Blockfrost.io API key (free tier available).
Usage
Client — Create a Payment
import { createPayment } from "@erudite-intelligence/x402-ada";
const paymentHeader = await createPayment({
senderAddress: "addr1q...",
senderPrivateKeyHex: "abcdef1234...",
recipientAddress: "addr1q...",
amountLovelace: "2000000", // 2 ADA
blockfrostApiKey: "mainnetXYZ...",
ttlSlots: 7200,
network: "mainnet",
});Server — Verify & Settle
import { verifyAndSettle } from "@erudite-intelligence/x402-ada";
const result = await verifyAndSettle({
paymentHeader: req.headers["x-payment"],
expectedRecipient: "addr1q...",
expectedAmountLovelace: "2000000",
blockfrostApiKey: "mainnetXYZ...",
network: "mainnet",
});
if (result.success) {
console.log("Settled:", result.txHash);
} else {
console.error("Payment failed:", result.error);
}Security
- Replay protection: In-memory Map with 1-hour TTL. Multi-instance deployments MUST use Redis/DB.
- Fail-closed: If balance verification or Blockfrost API fails, the payment is REJECTED.
- Output verification: Transaction outputs are inspected to confirm payment to the correct address and amount.
- TTL enforcement: Transactions past their TTL slot are rejected.
License
MIT — Erudite Intelligence LLC
