Quickstart
Table of contents
- Overview
Overview
Looking to get a Pi app built? Check out the following steps to get set up and developing on Pi.
Step 1: Getting On The Developer Portal
Access the Pi Developer Portal using the Pi Browser. Go to pi://develop.pi to visit the Pi Developer Portal. To register a new app, tap on the ‘New App’ button. To see information on an already created app, click on the tile for that app. This will bring you to the app’s dashboard page where you can see and edit information.
Step 2: Registering Your App
Fill in the required fields. The ‘App Network’ option lets you select the host network that your app is connecting to. It’s important to select the network, either Pi Mainnet or Pi Testnet, that you wish to deploy on as the Pi SDK will automatically connect your app to the corresponding network. Note: that an app can only connect to one network at a time, and once you’ve registered the app, this option cannot be changed.
Step 3: Getting Your API Key
At the bottom of your project’s app dashboard on the Developer Portal, you can see a section called ‘API Keys’. You will need it to access the Pi Backend as an application developer. Keep it safe! Anyone with this key can pretend to be you.
Step 4: Completing (most of) the Dev Portal Checklist
After you register your app, you can see your app in detail. Each app has its own ‘App Checklist’, which helps you keep track of required steps to successfully set up your app. To see the checklist, tap on the ‘App Checklist’ button located on the App Dashboard.
Step 5: Integrating Pi Into Your Application
The Pi SDK is javascript that you add to your page. First, call the SDK. Add this in the <head> of your page:
Next, authenticate the user. Add this in the <head> of your page:
In this code, onIncompletePaymentFound handles any pending payments from this authenticated user. You can select how you handle the payment: Cancel: Cancel, complete, or something else. Keep reading.
Step 6: Handling Payments
Finally - it’s time to handle payments! Payments have four steps. This section has everything you need, but understanding each step can help as you build more complex applications. To learn about each step, click here.
Create Payment:
Use the createPayment function in the Pi SDK. This function takes two arguments: a paymentData object (which includes the amount to be paid, a memo for users, and metadata for your own usage) and an object of callback functions.
Server-Side Approval:
The onReadyForServerApproval function gets called when the payment id is ready. Your app needs to pass the payment id and other relevant data to your app backend. The payment id should then be shared with the Pi API endpoint /payments/approve’
to signal that the app is ready to proceed with the payment.
User Interaction and Blockchain Transaction:
The Pi browser shows the payment detail page to a user, and we are waiting until the user signs the transaction.
Server-Side Completion:
The onReadyForServerCompletion function gets called after the blockchain transaction has been submitted to the Pi blockchain. Your job is again to pass any relevant data to your app server. On your server, you can verify the payment and deliver the item that was reserved for the user. In the end, you should complete the payment by letting the Pi server know that you have received the payment and delivered the item.
Please note that the actual implementation of these steps will depend on your specific app and server setup. Also, remember to handle any errors or cancellations that may occur during the payment process.
Additional Resources
Want to get more context on what your code could look like or what it could achieve. Head over to our Demo Apps and Blog to see other references including code examples.