
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
x402x-react
Advanced tools
React hooks for X402 Payment Protocol.
pnpm add x402x-react
import { useX402Payment } from 'x402x-react';
import { useWalletClient } from 'wagmi';
function PaymentComponent() {
const { data: walletClient } = useWalletClient();
const { mutate, isPending, error, data } = useX402Payment({
targetUrl: 'https://api.example.com/resource',
value: 1000000000000000000n, // 1 ETH
walletClient,
// Optional: specify payment type (default: 'permit')
paymentType: 'permit',
});
return (
<div>
<button
onClick={() => mutate()}
disabled={isPending || !walletClient}
>
{isPending ? 'Processing...' : 'Pay 1 ETH'}
</button>
{error && <div style={{ color: 'red' }}>Error: {error.message}</div>}
{data && (
<div style={{ color: 'green' }}>
Payment Successful! Tx: {data.txHash}
</div>
)}
</div>
);
}
useX402Payment(options)A React hook that wraps x402x-fetch to handle the payment flow. It uses @tanstack/react-query's useMutation under the hood.
UseX402PaymentOptions)| Property | Type | Required | Description |
|---|---|---|---|
targetUrl | string | Yes | The URL of the protected resource that requires payment. |
value | bigint | Yes | The maximum payment amount authorized (in wei). |
walletClient | WalletClient | Yes | The Viem WalletClient (usually from wagmi). |
paymentType | string | No | Payment method to use. Defaults to 'permit'. |
init | RequestInit | No | Standard Fetch options (headers, method, etc.). |
mutationOptions | UseMutationOptions | No | Additional options for React Query's useMutation. |
Returns a standard React Query mutation object containing:
mutate: Function to trigger the payment flow.mutateAsync: Async function to trigger payment and await result.data: The successful payment response (X402PaymentResponse).error: Error object if payment failed.isPending: Boolean indicating if payment is in progress.useMutation return values.X402PaymentResponse)On success, data will contain:
interface X402PaymentResponse {
success: boolean;
network: string;
payer: string;
txHash: string;
asset: string;
amount: string;
recipient: string;
description?: string;
}
The hook will throw an error in the following cases:
code !== 0).You can capture these errors using the onError callback in mutationOptions or by checking the error property returned by the hook.
FAQs
X402 Payment Protocol React Hooks
We found that x402x-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.