
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
x402-client
Advanced tools
Easy payment requests for x402 protocol on Solana. This package provides client-side utilities for making payment-gated requests to x402-enabled servers.
npm install @x402/client
import { X402Client, X402Wallet } from '@x402/client';
// Create or import wallet
const wallet = X402Wallet.fromPrivateKey(privateKey);
// or generate new wallet
const wallet = X402Wallet.create();
// Create client
const client = new X402Client({
wallet,
facilitatorUrl: 'http://localhost:3001'
});
// Pay and fetch resource
const response = await client.payAndFetch('http://localhost:3000/premium', {
amount: 0.01 // 0.01 SOL
});
console.log(response.data); // Premium content
Wallet management for x402 payments.
// Create new wallet
const wallet = X402Wallet.create();
// Import from private key
const wallet = X402Wallet.fromPrivateKey('base58-private-key');
// Import from mnemonic
const wallet = await X402Wallet.fromMnemonic('your twelve word mnemonic phrase');
// Get public key
const publicKey = wallet.getPublicKey();
// Sign message
const signature = await wallet.signMessage(messageBytes);
// Export wallet
const json = wallet.toJSON();
Client for making payment-gated requests.
const client = new X402Client({
wallet: myWallet,
facilitatorUrl: 'http://localhost:3001',
rpcUrl: 'https://api.devnet.solana.com', // optional
defaultExpiry: 300 // optional, 5 minutes default
});
// Make payment request
const response = await client.payAndFetch(url, {
amount: 0.01, // SOL amount
expiry: 600, // optional, seconds
resourceId: 'custom-id' // optional
});
// Manual payment creation
const paymentRequest = await client.createPaymentRequest(url, options, merchantAddress);
// Verify payment
const isValid = await client.verifyPayment(paymentRequest);
// Get wallet balance
const balance = await client.getBalance();
// Request airdrop (devnet only)
const signature = await client.requestAirdrop(1); // 1 SOL
import { X402Client, X402Wallet } from '@x402/client';
const wallet = X402Wallet.fromPrivateKey(process.env.PRIVATE_KEY!);
const client = new X402Client({
wallet,
facilitatorUrl: process.env.FACILITATOR_URL!
});
try {
const response = await client.payAndFetch('https://api.example.com/premium-data', {
amount: 0.01
});
console.log('Premium data:', response.data);
console.log('Transaction:', response.transactionSignature);
} catch (error) {
console.error('Payment failed:', error);
}
const response = await client.payAndFetch('https://api.example.com/resource', {
amount: 0.005,
expiry: 600, // 10 minutes
resourceId: 'custom-resource-id'
});
// Create payment request
const paymentRequest = await client.createPaymentRequest(
'https://api.example.com/resource',
{ amount: 0.01 },
'merchant-solana-address'
);
// Verify with facilitator
const isValid = await client.verifyPayment(paymentRequest);
if (isValid) {
// Make HTTP request with payment
const response = await client.makePaymentRequest(
'https://api.example.com/resource',
{ amount: 0.01 }
);
}
try {
const response = await client.payAndFetch(url, options);
} catch (error) {
if (error.message.includes('insufficient SOL')) {
console.log('Need more SOL in wallet');
} else if (error.message.includes('402')) {
console.log('Payment required but failed');
} else {
console.log('Other error:', error.message);
}
}
interface PaymentOptions {
amount: number; // SOL amount
expiry?: number; // seconds
resourceId?: string; // custom identifier
}
interface PaymentResponse<T> {
data: T; // response data
verified: boolean; // payment verification status
transactionSignature?: string; // Solana transaction hash
}
interface X402ClientConfig {
wallet: X402Wallet;
facilitatorUrl: string;
rpcUrl?: string; // default: devnet
defaultExpiry?: number; // default: 300 seconds
}
This package works in both Node.js and browser environments. For browsers, ensure you have proper polyfills for Node.js modules if needed.
MIT
FAQs
x402 client library for browser and Node.js - Easy payment requests
We found that x402-client 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

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.