payments.pay
Pay an x402-priced URL in USDC on Base using the active mandate
Scope: payments:spend
Pay an x402-priced URL. Loomal discovers the seller's 402 challenge, checks your mandate caps, signs the EIP-3009 USDC transfer on your project's smart account, retries with X-Payment, and returns the resource content plus cost and on-chain tx hash.
Returns a discriminated { ok, ... } body — branch on ok and read code on failure rather than treating non-success as an exception.
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
url | string | Yes | URL of the paid resource. Must respond with HTTP 402 in x402 format. |
dryRun | boolean | No | Validate mandate + balance + caps without signing or settling. |
Example
Agent: "Buy the search result for 'agentic commerce' from example.com/search."
-> payments.pay({ url: "https://example.com/search?q=agentic+commerce" })Returns — ok: true
{
"ok": true,
"status": 200,
"content": { "results": [/* ... */] },
"cost": { "amountUsdc": "0.05", "amountUsdcRaw": "50000", "network": "base" },
"txHash": "0x<onchain-settle-tx-hash>",
"payer": "0x<your-project-wallet>",
"recipient": "0x<seller-wallet>",
"resource": "https://example.com/search?q=agentic+commerce",
"balanceAfter": { "usdc": "9.95", "usdcRaw": "9950000" },
"mandate": { "mandateId": "m_abc", "remainingTodayUsdcRaw": "950000", "validUntil": "..." }
}Returns — ok: false
{
"ok": false,
"code": "mandate_per_call_exceeded",
"message": "Price 0.50 USDC exceeds maxPerCallUsdc 0.10",
"hint": "Raise maxPerCallUsdc on the mandate or pay a cheaper endpoint"
}Full code list: payments.pay SDK reference.