This package, pi-sdk-js, 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 frontend interface for initiating and completing Pi transactions. It does not include backend support and will not operate without it. Use one of the backend packages such as pi-sdk-nextjs, pi-sdk-express, pi-sdk-express, or pi-sdk-rails.
pi-sdk-js package to your appnpm install pi-sdk-jsyarn add pi-sdk-jswindow.Pi) is available in your HTML<head>
<!-- ... other <head> content (meta, title, styles, etc.) ... -->
<script src="https://sdk.minepi.com/pi-sdk.js"></script>
</head>This is required for all Pi SDK browser integrations.
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 } });The local REST endpoints that you must provide are described in the Official Pi SDK Docs.
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.PiSdkBase.user: PiUser | null – Current user after .connect()PiSdkBase.connected: boolean – Is SDK authenticated/connected?PiSdkBase.accessToken: string | null – Latest session access token (opaque bearer token)PiUser (Type)Represents an authenticated Pi user, at minimum { name: string, ... }.
PaymentData (Type)interface PaymentData {
amount: number;
memo: string;
metadata: Record<string, unknown>;
}import { ... } from 'pi-sdk-js'; no CommonJS support.window.Pi: The SDK does NOT bundle or polyfill the Pi Network global; you must include the Pi SDK <script> yourself.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.
This package is intended for browsers; headless use requires you to polyfill window and window.Pi.
See the complete API in source. Most advanced features are mapped, but basics are exposed as above for typical dApps.
For advanced integration patterns, see the pi-sdk-react package or your framework’s best practices.