Links

Using Push SDK (Gasless)

This section describes how to send a notification using the Push SDK.
Check out push-for-hackers/sdk-functionality repo for code coverage of all SDK functions. Check out @pushprotocol/restapi or @pushprotocol/socket for more examples.

Installation

Install the sdk restapi package and its peer dependencies in your app.
npm
yarn
npm install @pushprotocol/[email protected] ethers
yarn add @pushprotocol/[email protected] ethers
Note: If you wish to use ES6 Modules syntax, then inside package.json set “type” to “module”.

Import

import * as PushAPI from "@pushprotocol/restapi";

Sample Usage

In the code below, we'll send a notification to all subscribers of your channel, a broadcast notification. For different types of notifications and more examples, go to this page.
The PKey is the private key from the wallet you created a channel. The channel address is going to be the address of the wallet you created your channel.
import * as PushAPI from "@pushprotocol/restapi";
import * as ethers from "ethers";
const PK = 'your_channel_address_secret_key'; // channel private key
const Pkey = `0x${PK}`;
const _signer = new ethers.Wallet(Pkey);
const sendNotification = async() => {
try {
const apiResponse = await PushAPI.payloads.sendNotification({
signer: _signer,
type: 1, // broadcast
identityType: 2, // direct payload
notification: {
title: `[SDK-TEST] notification TITLE:`,
body: `[sdk-test] notification BODY`
},
payload: {
title: `[sdk-test] payload title`,
body: `sample msg body`,
cta: '',
img: ''
},
channel: 'eip155:5:0xD8634C39BBFd4033c0d3289C4515275102423681', // your channel address
env: 'staging'
});
} catch (err) {
console.error('Error: ', err);
}
}
sendNotification();
For sending different types of notifications, such as Targeted and Subset, and for more examples, go to the page below: