Skip to content

Skills marketplace: x402 micro-payment flow — agent invocation with on-chain payment proof #312

Description

@leocagli

Context

PR#304 (pending) adds the skill listing API. This issue specifies the payment flow: when an agent calls a skill from another agent, the x402 HTTP payment protocol handles the micro-payment automatically before the skill runs.

What to implement

Payment middleware (lib/marketplace/x402-middleware.ts)

When an agent calls callUrl from a listed skill:

  1. Attempt the HTTP request — if response is 402, capture the payment requirements
  2. Generate a Stellar payment transaction for priceXLM to the skill owner's wallet
  3. Attach the payment proof as an X-Payment header
  4. Retry the request

Route: POST /api/marketplace/skills/[skillId]/invoke

// Body: { agentId, payload }
// Validates payment, then proxies request to skill.callUrl

Payment ledger

Track each invocation: { agentId, skillId, amountXLM, txHash, invokedAt }

Acceptance criteria

  • Agent invokes skill → 402 received → payment sent → skill responds 200
  • Payment proof stored in invocation ledger
  • Insufficient balance → 402 returned to caller with { error: 'insufficient_balance' }
  • Unit test: mock x402 flow → invocation logged with correct txHash

🎁 Evidencia visual = reward extra

  • Si tu PR incluye video demo o capturas de pantalla mostrando la funcionalidad pedida funcionando end-to-end, va a ser considerado para rewards de GrantFox en esta issue. No es obligatorio, pero suma mucho para la evaluación.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions