INNER CODE UNIT · JavaScript
decimals
nirholas/XActions · packages/xactions-edge/index.js:62
const decimals = 6; // USDC on both supported chains
const amount = Number(first.maxAmountRequired ?? first.amount ?? 0) / 10 ** decimals;
const price = amount ? `$${amount.toFixed(6).replace(/0+$/, '').replace(/\.$/, '')}` : 'a fee';
const chains = accepts.map((entry) => NETWORK_NAMES[entry.network] || entry.network);
super(
`${tool} costs ${price} in USDC (${chains.join(' or ') || 'x402'}). `
+ 'Pay with an x402 client and retry: https://xactions.app/docs/guides/x402',
{ tool, status: 402 },
);
this.name = 'PaymentRequiredError';
this.price = price;
this.amount = amount;
this.currency = 'USDC';
this.networks = accepts.map((entry) => entry.network);
this.chains = chains;
this.accepts = accepts;
this.resource = payload?.resource?.url || first.resource || null;
}