@ldclabs/anda_x402
v0.7.0
Published
The Typescript version of the client SDK for the Anda x402.
Readme
@ldclabs/anda_x402
@ldclabs/anda_x402 is the Typescript version of the client SDK for Anda x402 facilitator.
It implements version 2 of the
x402 Protocol Specification
for the exact scheme on the icp:1 network.
Usage
import { X402Canister, X402_VERSION } from '@ldclabs/anda_x402'
const x402 = new X402Canister('ogkpr-lyaaa-aaaap-an5fq-cai', identity)
// What the facilitator implements, including the `icp:*` signer the payer
// must approve as their ICRC-2 spender.
const supported = await x402.getSupported()
// `paymentRequired` is the server's `PaymentRequired` object, carried by the
// base64-encoded `PAYMENT-REQUIRED` response header over HTTP.
const request = await x402.buildX402RequestFrom(paymentRequired, assetId)buildX402RequestFrom picks the accepts[] entry to pay:
- Entries for another network or asset, or whose reserved
extrakeys this SDK does not recognize, are skipped — another entry may still be payable. - When a resource offers both,
authorizationwins overupfront, so the funds move only after the resource has delivered. - Extensions advertised in
PaymentRequiredare echoed back in thePaymentPayload, as the protocol requires.
The mechanism supports assetTransferMethod: "icrc2" and the
authorization (default) and upfront payment flows. escrow is not
supported: a single ICRC-2 pull cannot express a deposit settle followed by a
final-charge settle.
License
Copyright © 2024-2025 LDC Labs.
Licensed under the MIT License. See LICENSE for details.
