npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@x1pays/sdk

v0.1.0

Published

TypeScript SDK for x402 payment protocol on X1 blockchain

Downloads

15

Readme

@x1pays/sdk

TypeScript SDK for the x402 payment protocol on X1 blockchain.

🚀 Features

  • ✅ Simple API for x402 payments
  • ✅ Sign and send payments with Solana keypairs
  • ✅ Automatic payment verification
  • ✅ Testnet and Mainnet support
  • ✅ TypeScript support with full type definitions
  • ✅ Lightweight and fast

📦 Installation

npm install @x1pays/sdk
# or
pnpm add @x1pays/sdk
# or
yarn add @x1pays/sdk

🔧 Quick Start

import { Keypair } from '@solana/web3.js';
import { getWithPayment, PayConfig } from '@x1pays/sdk';

// Load your wallet keypair
const payer = Keypair.fromSecretKey(/* your secret key */);

// Configure payment
const config: PayConfig = {
  facilitatorUrl: 'https://facilitator.x1pays.com',
  payTo: 'MERCHANT_ADDRESS_HERE',
  asset: 'wXNT_TOKEN_MINT_ADDRESS',
  network: 'x1-testnet', // or 'x1-mainnet'
  amountAtomic: '1000' // Amount in lamports (0.000001 wXNT)
};

// Make a payment-protected API call
const data = await getWithPayment(
  'https://api.example.com/protected-endpoint',
  payer,
  config
);

console.log('Response:', data);

📖 API Reference

getWithPayment(url, payer, config)

Makes an HTTP GET request with x402 payment authorization.

Parameters:

  • url (string): The API endpoint to call
  • payer (Keypair): Solana keypair for signing the payment
  • config (PayConfig): Payment configuration object

Returns: Promise - The API response data

Throws: Error if payment is not accepted (402 status)

signPayment(payer, payload)

Signs a payment payload with the payer's keypair.

Parameters:

  • payer (Keypair): Solana keypair for signing
  • payload (object): Payment payload to sign

Returns: string - Base58 encoded signature

PayConfig

Payment configuration interface:

interface PayConfig {
  facilitatorUrl: string;      // X1Pays facilitator URL
  payTo: string;                // Merchant wallet address
  asset: string;                // wXNT token mint address
  network?: 'x1-mainnet' | 'x1-testnet';  // Default: 'x1-mainnet'
  amountAtomic: string;         // Amount in lamports
}

💡 Examples

Basic Payment

import { Keypair } from '@solana/web3.js';
import { getWithPayment } from '@x1pays/sdk';

const payer = Keypair.generate(); // Or load from file/env

try {
  const response = await getWithPayment(
    'https://api.example.com/data',
    payer,
    {
      facilitatorUrl: 'http://localhost:4000',
      payTo: 'MerchantPublicKeyHere',
      asset: 'wXNT_MINT_ADDRESS',
      network: 'x1-testnet',
      amountAtomic: '1000' // 0.000001 wXNT
    }
  );
  
  console.log('Success:', response);
} catch (error) {
  console.error('Payment failed:', error);
}

Using Environment Variables

import { Keypair } from '@solana/web3.js';
import { getWithPayment } from '@x1pays/sdk';
import bs58 from 'bs58';

// Load keypair from environment
const secretKey = bs58.decode(process.env.WALLET_SECRET_KEY!);
const payer = Keypair.fromSecretKey(secretKey);

const config = {
  facilitatorUrl: process.env.FACILITATOR_URL!,
  payTo: process.env.MERCHANT_ADDRESS!,
  asset: process.env.WXNT_MINT!,
  network: process.env.NETWORK as 'x1-testnet' | 'x1-mainnet',
  amountAtomic: process.env.PAYMENT_AMOUNT!
};

const data = await getWithPayment('/api/endpoint', payer, config);

Error Handling

try {
  const data = await getWithPayment(url, payer, config);
  console.log('Payment successful:', data);
} catch (error) {
  if (error instanceof Error) {
    if (error.message.includes('402')) {
      console.error('Payment was rejected by the server');
    } else if (error.message.includes('network')) {
      console.error('Network error - check your connection');
    } else {
      console.error('Unknown error:', error.message);
    }
  }
}

🔐 Security Best Practices

  1. Never commit private keys - Use environment variables
  2. Validate merchant addresses - Ensure you're paying the correct merchant
  3. Use testnet first - Test your integration before going to mainnet
  4. Monitor spending - Track your payment amounts
  5. Secure keypair storage - Use secure key management for production

🌐 Network Configuration

Testnet

{
  network: 'x1-testnet',
  facilitatorUrl: 'http://localhost:4000', // Your testnet facilitator
  asset: 'TESTNET_WXNT_MINT'
}

Mainnet

{
  network: 'x1-mainnet',
  facilitatorUrl: 'https://facilitator.x1pays.com',
  asset: 'MAINNET_WXNT_MINT'
}

🛠️ Development

# Install dependencies
pnpm install

# Build the package
pnpm build

# Run tests
pnpm test

# Watch mode
pnpm dev

📚 Learn More

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT License - see LICENSE file for details

🔗 Links

💬 Support


Built with ❤️ by the X1Pays team