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

pi-sdk-js

v2.0.0

Published

A JavaScript class for handling front-end protocol for Pi transactions.

Readme

Pi Network JS SDK – Community Developer Guide

This package provides a fully-typed, modern ES module interface to the Pi Network protocol for browser or web-app integrations. It is intended for developers building applications that use the Pi browser extension or the window.Pi global API, and wish to use TypeScript or class-based control. It is part of the "Ten Minutes to Transactions" effort described in this video.

** This package only contains the front end interface for initiating and completing Pi transations. It does not include back end support and will not operate without it. ** Use one of the back end packages such as pi-sdk-nextjs or pi-sdk-rails.


🚀 Quick Start

  1. Install with yarn or npm

yarn add pi-sdk-js

or

npm install pi-sdk-js

2. **Ensure the global Pi SDK (`window.Pi`) is available in your HTML**
```html
<script src="https://sdk.minepi.com/pi-sdk.js"></script>
  1. Import and use the SDK in your project:

    import { PiSdkBase, PiUser, PaymentData } from 'pi-sdk-js';
    
    const pi = new PiSdkBase();
    await pi.connect();
    // Now PiSdkBase.user is available (or listen for onConnection)
    pi.createPayment({ amount: 1, memo: "Demo", metadata: { productId: 42 } });

📦 API Overview

Classes and Types

PiSdkBase (Class)

Core interface to Pi Network via the browser SDK. Example usage:

  • connect() – Initiates authentication and session handshake. Should be called on user intent (or mount).
  • createPayment(paymentData) – Begins a payment operation. All server callbacks are handled automatically via Pi's callback protocol.
  • Static helpers:
    • PiSdkBase.user: PiUser | null – Current user after .connect()
    • PiSdkBase.connected: boolean – Is SDK authenticated/connected?
    • PiSdkBase.accessToken: string | null – Latest session or payment JWT

PiUser (Type)

Represents an authenticated Pi user, at minimum { name: string, ... }.

PaymentData (Type)

interface PaymentData {
  amount: number;
  memo: string;
  metadata: Record<string, unknown>;
}

🔑 Key Details

  • ESM Only: Use import { ... } from 'pi-sdk-js'; no CommonJS support.
  • Depends on the global window.Pi: The SDK does NOT bundle or polyfill the Pi Network global; you must include the Pi SDK <script> yourself.
  • Callbacks & Events: Payment lifecycle events (approve, complete, cancel, error, incomplete) are managed via static methods—override or listen as needed.
  • No React dependency.

❓ FAQ

How do I mock window.Pi for testing/development?

Assign a stub to window.Pi with mock methods (see your test runner for examples). No real payments or network calls will be made.

What is required to run in Node.js?

This package is intended for browsers; headless use requires you to polyfill window and window.Pi.

Where are user roles or advanced Pi features?

See the complete API in source. Most advanced features are mapped, but basics are exposed as above for typical dApps.


📚 Further Resources

For advanced integration patterns, see the pi-sdk-react package or your framework's best practices.