x402-stellar
v0.2.0
Published
Core library for Stellar x402 payment protocol - Accept payments with 1 line of code
Maintainers
Readme
x402-stellar
Core library for the Stellar x402 payment protocol.
Installation
npm install x402-stellarUsage
Types and Schemas
import {
PaymentPayloadSchema,
PaymentRequirementsSchema,
type PaymentPayload,
type PaymentRequirements,
} from "x402-stellar";
// Validate a payment payload
const result = PaymentPayloadSchema.safeParse(payload);
if (result.success) {
const validPayload: PaymentPayload = result.data;
}Facilitator Client
import { useFacilitator } from "x402-stellar";
const { verify, settle, supported } = useFacilitator({
url: "http://localhost:4022",
});
// Get supported payment kinds
const kinds = await supported();
// Verify a payment
const verifyResult = await verify(paymentPayload, paymentRequirements);
// Settle a payment
const settleResult = await settle(paymentPayload, paymentRequirements);Network Configuration
import { STELLAR_NETWORKS } from "x402-stellar";
const testnetConfig = STELLAR_NETWORKS["stellar-testnet"];
console.log(testnetConfig.horizonUrl);
// https://horizon-testnet.stellar.orgToken Catalog (USDC)
import { STELLAR_TOKENS, getTokenBySymbol } from "x402-stellar";
// Get USDC contract addresses
const usdcTestnet = STELLAR_TOKENS["stellar-testnet"].USDC;
console.log(usdcTestnet.address);
// CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA
const usdcMainnet = getTokenBySymbol("stellar", "USDC");
console.log(usdcMainnet?.address);
// CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75Exports
x402-stellar- Main entry point with all exportsx402-stellar/types- Types and Zod schemas onlyx402-stellar/shared- Shared utilities (base64, JSON)x402-stellar/verify- Facilitator client
License
MIT
