Skip to main content

Initialize user overview

Before you can start sending notifications, or receiving notifications from your preferred protocol, you will need to initialize a user or re-authenticate the user. To do so you will use PushAPI.initialize call from @pushprotocol/restapi package.

Initialize user API

import { PushAPI, CONSTANTS } from "@pushprotocol/restapi";

// PushAPI.initialize(signer, {options?});
// signer - pass the signer from your app and set env to 'CONSTANTS.ENV.PROD' for mainnet app
// options? - optional, can pass initialization parameters for customization
const userAlice = await PushAPI.initialize(signer, { env: CONSTANTS.ENV.STAGING });

The function automatically initializes and returns the Push user profile object if one doesn't exist for the user or alternatively creates a new profile if the user has not been onboarded to Push network. This profile is used to interact with all function calls moving forward.

Setting the right environment

Push Network operates on the following environments —

  • Production - You will need to set env in options object to 'prod' to enable mainnet apps communication.
  • Staging - Set by default, can omit options if testing your app on testnet.

Initialize user parameters

When initializing your user, you can customize the process using several parameters. Here's a breakdown:

signerSignerType--EthersV5 or Viem Signer
optionsPushAPIInitializeProps--Optional configuration properties for initializing the PushAPI.
-options.envENVstagingAPI env - 'prod' or 'staging'
-options.progressHook(progress: ProgressHookType) => void-A callback function to receive progress updates during initialization.
-options.accountstring-The account to associate with the PushAPI. If not provided, it is derived from signer.
-options.versionstringENC_TYPE_V3The encryption version to use for the PushAPI
-options.versionMeta{ NFTPGP_V1 ?: password: string }-Metadata related to the encryption version, including a password if needed.
-options.autoUpgradebooleantrueIf true, upgrades encryption keys to latest encryption version
-options.originstring-Specify origin or source while creating a Push Profile
-options.streamOptions{ listen?: STREAM[]; filter?: { channels?: string[]; chats?: string[]; }; connection?: { auto?: boolean; retries?: number; }; raw?: boolean; env?: ENV; enabled?: boolean;}-Specify steam options and filters while creating a Push Profile

Note: Parameters in this style are mandatory.

Expected response
200 OK

Initialize user interface

* Initialization Parameters for PushAPI

* Specifies the type of signer.
* Choose between EthersV5 or Viem Signer.
type Signer = SignerType;

interface PushAPIInitializeProps {
* Sets the API environment.
* Options: 'prod', 'staging', 'dev'
* Default: 'staging'
env?: ENV;

* A callback function to receive updates during the initialization process.
progressHook?: (progress: ProgressHookType) => void;

* The account you want to link with the PushAPI.
* If left empty, it'll use the account associated with your signer.
account?: string;

* Specifies the encryption version for the PushAPI.
* Default: 'ENC_TYPE_V3'
version?: string;

* Provides additional data related to your chosen encryption version,
* like a necessary password.
versionMeta?: {
password: string;

* When set to true, the system will automatically upgrade encryption keys
* to the latest available encryption version.
* Default: true
autoUpgrade?: boolean;

* Defines the origin or source when setting up a Push Profile.
origin?: string;

* Defines stream options or filters when setting up a Push Profile.
streamOptions?: PushStreamInitializeProps;

* Initializes the PushAPI with given parameters.
* @param signer The type of signer (EthersV5 or Viem Signer).
* @param options Optional configurations for initializing the PushAPI.
function initializePushAPI(signer: Signer, options?: PushAPIInitializeProps) {
// Initialization logic here