A backend client for interacting with the Pi Network Platform and Stellar APIs.
npm install @pinetwork-js/nodepi
yarn add @pinetwork-js/nodepi
const { Client } = require('@pinetwork-js/nodepi');
// TypeScript or ESM support
import { Client } from '@pinetwork-js/nodepi';
To use the client, you need to instanciate it with your Pi Network Platform API key and other optional configuration options. If you want the Stellar client to filter just the events associated with the wallet of your application, you can specify its private key (or passphrase) in the optional configuration options.
// With Stellar application wallet filter
const client = new Client('api-key', {
stellar: {
privateKey:
'private-key',
},
});
// Without Stellar application wallet filter
const client = new Client('api-key');
client.stellar.on('ready', () => {
console.log('Nodepi is ready to be used!');
});
By default, the Stellar client does not listen to any events, but you can request to listen to any event in this list (beware though, the Pi Network blockchain API has a rate limit of 3600 requests per hour, or one request per second).
// Request to listen only to new operations and transactions
const client = new Client('api-key', {
stellar: {
events: ['operations', 'transactions'],
},
});
client.stellar.on('ready', () => {
console.log('Nodepi is ready to be used!');
});
client.stellar.on('operation', (operation) => {
console.log('New operation', operation)
});
client.stellar.on('transaction', (transaction) => {
console.log('New transaction', transaction)
});