@pinetwork-js/nodepi

A backend client for interacting with the Pi Network Platform and Stellar APIs.

Usage no npm install needed!

<script type="module">
  import pinetworkJsNodepi from 'https://cdn.skypack.dev/@pinetwork-js/nodepi';
</script>

README

Nodepi

GitHub npm

A backend client for interacting with the Pi Network Platform and Stellar APIs.

Installation

Install with npm or yarn:

npm install @pinetwork-js/nodepi
yarn add @pinetwork-js/nodepi

Example usage

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)
});

Links