feat(x402): optional beforePayment hook to approve or block a payment by snefhew · Pull Request #1577 · coinbase/agentkit · GitHub
Skip to content

feat(x402): optional beforePayment hook to approve or block a payment - #1577

Open
snefhew wants to merge 1 commit into
coinbase:mainfrom
factline-dev:x402-before-payment-hook
Open

snefhew wants to merge 1 commit into
coinbase:mainfrom
factline-dev:x402-before-payment-hook

Conversation

@snefhew

@snefhew snefhew commented Oct 19, 2026

Copy link
Copy Markdown

Closes #1576

Adds an optional beforePayment (TypeScript) / before_payment (Python) field to the x402 action provider config. The provider builds its x402 client internally, so users could not reach the SDK's existing hook; this passes the function to x402Client.onBeforePaymentCreation / x402ClientSync.on_before_payment_creation. Returning { abort: true, reason } (TS) or an AbortResult (Python) blocks the payment before it is signed. Uses: screening payTo against a sanctions list, per-seller spend policies, audit logging.

x402ActionProvider({
  maxPaymentUsdc: 1,
  beforePayment: async ({ selectedRequirements }) => {
    if (blocked(selectedRequirements.payTo)) return { abort: true, reason: "payTo not allowed" };
  },
});
  • No new dependencies; no behaviour change when the field is not set.
  • The TS type comes from the SDK: Parameters<x402Client["onBeforePaymentCreation"]>[0].
  • Tests (TS and Python): the hook is registered when configured and not otherwise.
  • Changeset and changelog fragment included.

Checked locally: jest src/action-providers/x402 (23 passed), tsc --noEmit, eslint, prettier; pytest tests/action_providers/x402 (12 passed), ruff check and format.

🤖 Generated with Claude Code

Adds an optional beforePayment (TypeScript) / before_payment (Python) config field to the x402 action provider. It is registered on the x402 client with onBeforePaymentCreation / on_before_payment_creation, so a check can block a payment before it is signed. No behaviour change when unset.

Closes coinbase#1576
@snefhew
snefhew requested a review from murrlincoln as a code owner October 19, 2026 17:53
@cb-heimdall

Copy link
Copy Markdown

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider python typescript labels Oct 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation python typescript

Development

Successfully merging this pull request may close these issues.

x402 action provider: optional beforePayment hook to approve or block a payment

2 participants