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.
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.