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 🙏

© 2026 – Pkg Stats / Ryan Hefner

my-gateway-sdk

v1.0.3

Published

Crypto Payment Gateway SDK

Readme

Crypto Payment Gateway SDK

A simple way for merchants to accept crypto payments on-chain using Next.js, wagmi, viem, react-query, and Solidity smart contracts.
This SDK provides ready-to-use hooks like usePay, useWithdraw, and useMerchantBalance for quick integration.


📦 Installation

# Step 1: Create a Vite project
npm create vite@latest my-cryptoproject
cd my-cryptoproject

# Step 2: Install dependencies
npm install wagmi viem @tanstack/react-query my-gateway-sdk


⚙️ Setup

In your main entry file (main.tsx or index.tsx):

import React from "react";
import ReactDOM from "react-dom/client";
import { WagmiProvider, createConfig, http } from "wagmi";
import { sepolia } from "wagmi/chains";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import App from "./App";

const config = createConfig({
  chains: [sepolia],
  transports: {
    [sepolia.id]: http() // Replace with your Alchemy/Infura URL for reliability
  }
});

const queryClient = new QueryClient();

ReactDOM.createRoot(document.getElementById("root")!).render(
  <React.StrictMode>
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>
        <App />
      </QueryClientProvider>
    </WagmiProvider>
  </React.StrictMode>
);

🔑 Wallet Connection

Use wagmi to connect/disconnect wallets.

import { useConnect, useAccount, useDisconnect } from "wagmi";
import { InjectedConnector } from "wagmi/connectors/injected";

export function ConnectButton() {
  const { connect } = useConnect({ connector: new InjectedConnector() });
  const { address, isConnected } = useAccount();
  const { disconnect } = useDisconnect();

  if (isConnected) {
    return (
      <div>
        <p>Connected: {address}</p>
        <button onClick={() => disconnect()}>Disconnect</button>
      </div>
    );
  }

  return <button onClick={() => connect()}>Connect Wallet</button>;
}

💰 Merchant Balance

Fetch merchant balance using the SDK.

import { useMerchantBalance } from "my-gateway-sdk";

function MerchantDashboard({ merchant }: { merchant: `0x${string}` }) {
  const { balance, isLoading, refetch } = useMerchantBalance(merchant);

  if (isLoading) return <p>Loading...</p>;
  return (
    <div>
      <p>Merchant Balance: {balance?.toString()} wei</p>
      <button onClick={() => refetch()}>Refresh</button>
    </div>
  );
}

💸 Accept Payments

Use the usePay hook to send payments to a merchant.

import { usePay } from "my-gateway-sdk";

export function PayButton() {
  const { pay, isPending, isConfirming } = usePay();

  const handlePay = async () => {
    try {
      // Pay 0.01 ETH (in wei)
      await pay("0xMerchantRegisteredWalletAddress", BigInt("10000000000000000"));
    } catch (err) {
      console.error("Payment failed:", err);
    }
  };

  return (
    <button onClick={handlePay} disabled={isPending || isConfirming}>
      {isPending ? "Sending..." : isConfirming ? "Confirming..." : "Pay"}
    </button>
  );
}

🏦 Withdraw Funds

Merchants can withdraw their funds with the useWithdraw hook.

import { useWithdraw } from "my-gateway-sdk";

export function WithdrawButton() {
  const { withdraw, isPending, isConfirming } = useWithdraw();

  const handleWithdraw = async () => {
    try {
      // Withdraw 0.05 ETH (in wei)
      await withdraw(BigInt("50000000000000000"));
    } catch (error) {
      console.error("Withdraw failed:", error);
    }
  };

  return (
    <button onClick={handleWithdraw} disabled={isPending || isConfirming}>
      {isPending ? "Withdrawing..." : isConfirming ? "Confirming..." : "Withdraw"}
    </button>
  );
}

📂 Example App
import { ConnectButton } from "./ConnectButton";
import MerchantDashboard from "./MerchantDashboard";
import { PayButton } from "./Pay";
import { WithdrawButton } from "./Withdraw";

function App() {
  return (
    <div>
      <h1>Crypto Payment Gateway</h1>
      <ConnectButton />
      <MerchantDashboard merchant="0x1234...abcd" />
      <PayButton />
      <WithdrawButton />
    </div>
  );
}

export default App;