Get started with the x402 Solana SDK in minutes
Install the x402 Solana SDK package:
npm install @x402/solana-sdk
The SDK supports 6 wallets: Phantom, Solflare, Backpack, Glow, Slope, and Ledger. Use the wallet adapter:
import { useWallet } from '@solana/wallet-adapter-react';
import { WalletButton } from '@x402/solana-sdk/components';
function MyComponent() {
const { publicKey, signTransaction } = useWallet();
if (!publicKey) {
return <WalletButton />;
}
return <div>Connected: {publicKey.toBase58()}</div>;
}The wallet adapter automatically detects installed wallets and provides a unified interface.
Create a payment invoice using createInvoice():
import { createInvoice } from '@x402/solana-sdk';
const invoice = await createInvoice({
merchantId: 'merchant-123',
amount: '1.0',
token: 'USDC',
memo: 'Payment for service'
});
console.log('Invoice ID:', invoice.id);
console.log('Amount:', invoice.amount);
console.log('Status:', invoice.status);Monitor invoice status changes using watchInvoice():
import { watchInvoice } from '@x402/solana-sdk';
watchInvoice(invoice.id, (status) => {
console.log('Invoice status:', status);
if (status === 'paid') {
console.log('Payment confirmed!');
}
});