Skip to main content
Use custom hooks to implement project-specific behavior in payment lifecycle phases.
import type { ClientHook } from '@armory-sh/client-hooks';

const customHook: ClientHook = {
  name: 'require-premium-route',
  onPaymentRequired: async (context) => {
    const url = typeof context.url === 'string' ? context.url : context.url.toString();

    if (!url.includes('/premium')) {
      return;
    }
  },
  onError: async (context) => {
    console.error('[hook-error]', context.phase, context.error);
  }
};
For custom x402 extension payload fields, use createCustomHook from @armory-sh/extensions.