Using Neo Cast SDK (Gasless)

Sending Gasless Notifications Using the Neo Cast SDK

In this section, we'll describe how to send notifications using the Neo Cast SDK. This SDK enables you to send notifications programmatically. Here are the steps:

Installation: First, install the @Neo Castprotocol/restapi package and its peer dependencies in your app using npm.

npm install @NeoCastprotocol/restapi@latest ethers

Note: If you prefer to use ES6 Modules syntax, set the "type" in your package.json to "module".

Import the SDK: Import the necessary modules from the SDK in your code.

import * as NeoCastAPI from "@NeoCastprotocol/restapi";

Sample Usage: Below is an example of how to send a broadcast notification using the NeoCast SDK. For different types of notifications and more examples, you can refer to the provided documentation.

import * as NeoCastAPI from "@NeoCastprotocol/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 NeoCastAPI.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();

This code sends a broadcast notification to all subscribers of your channel. Modify the type and identityType fields to send different types of notifications like Targeted and Subset.

For more examples and details, you can refer to the provided documentation and repository.

Last updated