-
Notifications
You must be signed in to change notification settings - Fork 1
SDK Reference
Table of Contents
The Pi Network SDK is a JavaScript library that allows developers to integrate Pi Network features into their web applications. The SDK provides a set of methods that can be used to authenticate users, create payments, open share dialogs, and more.
To install the Pi Network SDK, add the following script tag to your HTML document:
<script src="https://sdk.minepi.com/pi-sdk.js"></script>Once the SDK is installed, you can initialize Pi:
Pi.init({ version: "2.0", sandbox: false }); //Set sandbox to true if deploying in a sandbox enviromentThe Pi class provides a number of methods that can be used to interact with Pi Network. For example, to authenticate a user, you can use the authenticate method:
Pi.authenticate(['payments'], (error, result) => {
if (error) {
// Handle the error
} else {
// The user has been authenticated
}
});(Development)
- Purpose: The sandbox allows you to test and develop your app in a simulated environment before deploying it to production.
-
Configuration:
- Set the
sandbox: trueflag in your SDK initialization. - Obtain your Sandbox URL from the Developer Portal.
- Set the
-
Sandbox Authorization: Follow these steps:
- Open the Pi App on your mobile device.
- Navigate to Pi Utilities.
- Click "Authorize Sandbox" and follow the instructions.
- Authentication: Pi.authenticate()
- App Presence: Pi.checkUserHasMiningApp(), Pi.checkUserHasPiBrowser()
- Clipboard: Pi.copyText()
- Payments: Pi.createPayment()
- App Info: Pi.getPiHostAppName(), Pi.getPiHostAppInfo()
- Initialization: Pi.init()
- Features: Pi.nativeFeaturesList()
- User Actions: Pi.openConversation(), Pi.openShareDialog(), Pi.openUrlInSystemBrowser(), Pi.requestPermission(), Pi.scanQrCode()
authenticate(t: string[], n?: (c: any) => any): Promise<{
user: any;
accessToken: string;
}>;The authenticate method in pi-sdk authenticates the user and returns a promise that resolves to an object containing the user's data and an access token.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string[] |
An array of scopes to request. |
n |
(c: any) => any |
A callback function that is called if the user cancels the authentication process. |
Returns:
AuthResult A promise that resolves to an object containing the user's data and an access token.
checkUserHasMiningApp(): Promise<{
userHasMiningApp: boolean;
}>;The checkUserHasMiningApp method in pi-sdk checks if the user has the Pi Mining App installed and returns a promise that resolves to an object indicating whether the user has the app installed.
Returns:
A promise that resolves to an object indicating whether the user has the Pi Mining App installed.
checkUserHasPiBrowser(): Promise<{
userHasPiBrowser: boolean;
}>;The checkUserHasPiBrowser method in pi-sdk checks if the user has the Pi Browser installed and returns a promise that resolves to an object indicating whether the user has the browser installed.
Returns:
A promise that resolves to an object indicating whether the user has the Pi Browser installed.
copyText(t: string): Promise<void>;The copyText method in pi-sdk copies the specified text to the clipboard and returns a promise that resolves when the text has been copied.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string |
The text to copy to the clipboard. |
Returns:
A promise that resolves when the text has been copied.
createPayment(t: any, n?: (c: any) => any): c;The createPayment method in pi-sdk creates a new payment and returns a promise that resolves to a payment object.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
any |
The payment data. |
n |
(c: any) => any |
A callback function that is called if the user cancels the payment process. |
Returns:
PaymentDTO A promise that resolves to a payment object.
getPiHostAppName(): string | undefined;The getPiHostAppName method in pi-sdk gets the name of the Pi host app and returns a string representing the name of the app.
Returns:
A string representing the name of the Pi host app.
getPiHostAppInfo(): Promise<{
hostApp: string;
}>;The getPiHostAppInfo method in pi-sdk gets the information about the Pi host app and returns a promise that resolves to an object containing the information.
Returns:
A promise that resolves to an object containing the information about the Pi host app.
init(t: {
version: string;
sandbox?: boolean;
}): Promise<void>;The init method in pi-sdk initializes the SDK and returns a promise that resolves when the SDK is initialized.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
`{ | |
| version: string; | ||
| sandbox?: boolean; | ||
| }` | The initialization options. |
Returns:
A promise that resolves when the SDK is initialized.
nativeFeaturesList(): Promise<string[]>;The nativeFeaturesList method in pi-sdk gets a list of the native features that are supported by the SDK and returns a promise that resolves to an array of strings representing the features.
Returns:
A promise that resolves to an array of strings representing the native features that are supported by the SDK.
openConversation(t: string): Promise<void>;The openConversation method in pi-sdk opens a conversation with the specified conversation ID and returns a promise that resolves when the conversation is opened.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string |
The conversation ID. |
Returns:
A promise that resolves when the conversation is opened.
openShareDialog(t: string, n: string): Promise<void>;The openShareDialog method in pi-sdk opens a share dialog with the specified title and sharing message and returns a promise that resolves when the dialog is opened.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string |
The title of the share dialog. |
n |
string |
The sharing message. |
Returns:
A promise that resolves when the share dialog is opened.
openUrlInSystemBrowser(t: string): Promise<void>;The openUrlInSystemBrowser method in pi-sdk opens the specified URL in the system browser and returns a promise that resolves when the URL is opened.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string |
The URL to open. |
Returns:
A promise that resolves when the URL is opened.
requestPermission(t: string): Promise<boolean>;The requestPermission method in pi-sdk requests the specified permission and returns a promise that resolves to a boolean indicating whether the permission was granted.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string |
The permission to request. |
Returns:
A promise that resolves to a boolean indicating whether the permission was granted.
scanQrCode(t?: any): Promise<string>;The scanQrCode method in pi-sdk scans a QR code and returns a promise that resolves to a string representing the scanned data.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
any |
The configuration options for the QR code scanner. |
Returns:
A promise that resolves to a string representing the scanned data.
- π Home - Complete developer handbook
- π Community Support - Get help from Pi developers
- π Authorization - Authentication & security patterns
- π API Reference - Complete REST API documentation
- β‘ SDK Reference - JavaScript SDK comprehensive guide
- π Data Types - Object structures & schemas
- π Pi Browser Detection - Build hybrid Web2/Web3 apps
- π Migration Guide - Upgrade to hybrid architecture
- π» Code Examples - Production-ready samples & templates
- π What is PiNet? - Cross-platform app accessibility
- π³ What is PiWallet? - Pi Network wallet integration
- π° Payments Overview - Transaction handling guide
- π¬ Chat Rooms for Apps - Community engagement features
- π Mainnet vs. Testnet - Environment selection guide
- π Developer Terms - Terms of service
- βοΈ Social Chain ToS - Platform terms
- π Whitepaper - Pi Network foundations