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 extra keys this
SDK does not recognize, are skipped — another entry may still be payable.
When a resource offers both, authorization wins over upfront, so the
funds move only after the resource has delivered.
Extensions advertised in PaymentRequired are echoed back in the
PaymentPayload, 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.