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

@0205miss/pi_net_sdk

v2.0.2

Published

Pi Network SDK for interacting with Pi Network APIs

Readme

Pi Network SDK

A TypeScript SDK for interacting with the Pi Network APIs, enabling payments, wallet transactions, and more.

Installation

npm i @0205miss/pi_net_sdk

Usage

Below are examples demonstrating how to use the Pi Network SDK. All examples use the named export piSDK, which is a pre-instantiated instance of the PiSDK class. You can also import the PiSDK class to create your own instances if needed.

Initializing the SDK

Initialize the SDK with your desired configuration (e.g., version and sandbox mode).

import { piSDK } from '@0205miss/pi_net_sdk';

async function initSDK() {
  try {
    await piSDK.init({
      version: '2.0',
      sandbox: true // Use sandbox mode for testing
    });
    console.log('Pi SDK initialized successfully');
  } catch (error) {
    console.error('Initialization failed:', error);
  }
}

initSDK();

Authenticating a User

Authenticate a user with specific scopes (e.g., payments, username) and handle incomplete payments.

import { piSDK } from '@0205miss/pi_net_sdk';

async function authenticateUser() {
  try {
    const scopes = ['payments', 'username'];
    const onIncompletePaymentFound = (payment: any) => {
      console.log('Incomplete payment found:', payment);
      // Handle incomplete payment (e.g., notify user or resume flow)
    };

    const authResult = await piSDK.authenticate(scopes, onIncompletePaymentFound);
    console.log('Authenticated user:', authResult.user.uid);
    console.log('Access token:', authResult.accessToken);
  } catch (error) {
    console.error('Authentication failed:', error);
  }
}

authenticateUser();

Creating a Payment

Create a payment flow, including callbacks for server approval, completion, errors, and cancellation.

import { piSDK } from '@0205miss/pi_net_sdk';

async function createPayment() {
  try {
    // Ensure SDK is initialized and user is authenticated with 'payments' scope
    await piSDK.init({ version: '2.0', sandbox: true });
    await piSDK.authenticate(['payments'], (payment) => console.log('Incomplete payment:', payment));

    const paymentData = {
      amount: 10, // Amount in Pi
      memo: 'Test payment',
      metadata: { orderId: '12345' },
      uid: 'user123' // User ID from authentication
    };

    const callbacks = {
      onReadyForServerApproval: (paymentId: string) => {
        console.log('Ready for server approval:', paymentId);
        // Send paymentId to your server for approval
      },
      onReadyForServerCompletion: (paymentId: string, txid: string) => {
        console.log('Ready for server completion:', paymentId, txid);
        // Send paymentId and txid to your server to complete the transaction
      },
      onError: (error: Error, payment?: any) => {
        console.error('Payment error:', error, payment);
      },
      onCancel: (paymentId: string) => {
        console.log('Payment cancelled:', paymentId);
      }
    };

    const paymentFlow = piSDK.createPayment(paymentData, callbacks);
    console.log('Payment flow started');
  } catch (error) {
    console.error('Payment creation failed:', error);
  }
}

createPayment();

Submitting a Wallet Transaction

Submit a transaction using a Stellar XDR string (e.g., for blockchain operations).

import { piSDK } from '@0205miss/pi_net_sdk';

async function submitTransaction() {
  try {
    // Ensure SDK is initialized
    await piSDK.init({ version: '2.0', sandbox: true });

    // Example XDR (replace with actual XDR from your application)
    const xdr = 'AAAA...'; // Stellar transaction XDR

    const result = await piSDK.Wallet!.submitTransaction(xdr);
    console.log('Transaction submitted:', result);
  } catch (error) {
    console.error('Transaction submission failed:', error);
  }
}

submitTransaction();

Opening a Share Dialog

Prompt the user to share content via the Pi Network.

import { piSDK } from '@0205miss/pi_net_sdk';

async function openShareDialog() {
  try {
    await piSDK.init({ version: '2.0', sandbox: true });
    await piSDK.openShareDialog('My App', 'Check out my awesome app on Pi Network!');
    console.log('Share dialog opened');
  } catch (error) {
    console.error('Failed to open share dialog:', error);
  }
}

openShareDialog();

Using the PiSDK Class Directly

If you need multiple SDK instances, import and instantiate the PiSDK class.

import { PiSDK } from '@0205miss/pi_net_sdk';

async function customInstance() {
  const customSDK = new PiSDK();
  try {
    await customSDK.init({ version: '2.0', sandbox: false });
    console.log('Custom SDK instance initialized');
  } catch (error) {
    console.error('Initialization failed:', error);
  }
}

customInstance();

Features

  • Authenticate users with Pi Network.
  • Create and manage payments.
  • Submit wallet transactions.
  • Access native features like QR code scanning, ads, and share dialogs.
  • Track user interactions and locations.
  • Support for both sandbox and production environments.

Requirements

  • Node.js >= 18.x
  • A Pi Network developer account
  • TypeScript (optional, for type safety)

Development Setup

  1. Clone the repository:

    git clone https://github.com/0205miss/pi_net_sdk.git
    cd pi_net_sdk
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build

Contributing

Contributions are welcome! Please submit issues and pull requests to https://github.com/0205miss/pi_net_sdk.

License

MIT