Observed since 20 Oct, 22:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Pi Network SDK for interacting with Pi Network APIs
A TypeScript SDK for interacting with the Pi Network APIs, enabling payments, wallet transactions, and more.
npm i @0205miss/pi_net_sdk
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.
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();
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();
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();
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();
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();
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();
Clone the repository:
git clone https://github.com/0205miss/pi_net_sdk.git
cd pi_net_sdk
Install dependencies:
npm install
Build the project:
npm run build
Contributions are welcome! Please submit issues and pull requests to https://github.com/0205miss/pi_net_sdk.
MIT
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:7aa5f0c637402cf228d9a8b0a7db51273abaf8cdc4744e9346b8d627a01d73ef