The Pi SDK provides all of the functionality for your app to operate in
the Pi Ecosystem. This page presumes that pi-sdk.js has been loaded into
the browser.
This guide demonstrates how to integrate the Pi SDK into many application frameworks. This example shows how to initialize the Pi SDK, authenticate a Pioneer, and create a payment request inside a Pi app.
The pi-sdk-js
package
is part of the “Ten Minutes to Transactions” effort described in this
video.
If you, or your GenAI agent, are planning to use the Pi SDK modules in this documentation for your app, it is highly suggested that you use this package rather than implement transaction processing by hand with the core Pi SDK. The three way handshake between client, server, and the Pi servers required is provded for you.
Note: Pi SDK authentication and payment features require the application to run inside the Pi Browser.
All methods below are called via window.Pi (not statically).
.init(options)window.Pi.init({ version: '2.0', sandbox?: boolean })
version (string, required) – SDK protocol versionsandbox (boolean, optional).authenticate(scopes, onIncompletePaymentFound)window.Pi.authenticate([
'payments', // Required for payment flows
'username', // Get user info
'roles', 'wallet_address', ... // Additional scopes
], onIncompletePaymentFound)
.then(({ user, accessToken }) => { ... });
scopes (array of strings): Permissions to request (at least 'payments', 'username')onIncompletePaymentFound (function, optional): Callback invoked if any unfinished payment should be handled{ user, accessToken }Important: You must successfully authenticate the user before performing any user-related actions (for example, reading their info or initiating a payment). The first time a user authenticates, Pi Browser shows a consent dialog asking them to share their data with your app.
.createPayment(paymentData, callbacks)window.Pi.createPayment(paymentData, {
onReadyForServerApproval: (paymentId) => { ... },
onReadyForServerCompletion: (paymentId, txid) => { ... },
onCancel: (paymentId) => { ... },
onError: (error, paymentData) => { ... }
});
paymentData (object): Payment details, e.g. { amount, memo, metadata }callbacks (object): Required handler functions (see above)Looking for App-to-User (A2U) payouts?
Pi.createPaymentcovers User-to-App (U2A) flows. For payments from your app to users (A2U), use the Platform API from your backend. See Advanced Payments for details.
onReadyForServerApproval(paymentId) – Called when payment is ready for backend approvalonReadyForServerCompletion(paymentId, txid) – Called when network waits for backend to mark completeonCancel(paymentId) – Payment canceled by useronError(error, paymentData) – Error in payment processonIncompletePaymentFound(paymentDTO) – (from .authenticate) handle unfinished payment<script src="/pi-sdk.js"></script>
<script>
window.Pi.init({ version: "2.0", sandbox: true });
window.Pi.authenticate(["payments", "username"], function onPaymentFound(payment) {
// Handle an incomplete payment
}).then(({ user, accessToken }) => {
// Ready to make payments
window.Pi.createPayment(
{ amount: 0.02, memo: "Pi Example", metadata: { order_id: 42 } },
{
onReadyForServerApproval: (paymentId) => {
/* POST to /approve */
},
onReadyForServerCompletion: (paymentId, txid) => {
/* POST to /complete */
},
onCancel: (paymentId) => {
console.log("Canceled", paymentId);
},
onError: (error) => {
console.error(error);
},
},
);
});
</script>
| Property / Function | Description / Methods |
|---|---|
window.Pi |
Main SDK instance |
.init |
Initialize SDK |
.authenticate |
User login and canonical Pi integration |
.createPayment |
Start payment flow |
.Ads |
Ad management (isAdReady, requestAd, showAd) |
.openShareDialog |
Open Pi share dialog |
.openConversation |
Pi chat/conversation integration |
.nativeFeaturesList |
List supported native features |
.requestPermission |
Request native OS permission |
.copyText |
Copy text to clipboard |
.openUrlInSystemBrowser |
Open link in external browser |
Functionality is inferred from SDK patterns, public documentation, and code inspection. Actual API may differ slightly depending on SDK version. Not all methods will be present/documented if not supported by a particular build.
For question about specific methods, advanced usage, or backend integration, see core SDK documentation or contact Pi Network developer support.