Initialize user overview
Before you can start sending messages, or create conditional access group for your community, or send those chat requests to Vitalik.eth
. 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
- js
import { PushAPI, CONSTANTS } from "@pushprotocol/restapi";
// PushAPI.initialize(signer, {options?});
// signer - pass the signer from your app and set env to 'prod' for mainnet app
// options? - optional, can pass initialization parameters for customization
const userAlice = await PushAPI.initialize(signer, { env: "prod" });
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
inoptions
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:
Param | Type | Sub-Type | Default | Remarks |
---|---|---|---|---|
signer | SignerType | - | - | EthersV5 or Viem Signer |
options | PushAPIInitializeProps | - | - | Optional configuration properties for initializing the PushAPI. |
- | options.env | ENV | staging | API env - 'prod' or 'staging' |
- | options.progressHook | (progress: ProgressHookType) => void | - | A callback function to receive progress updates during initialization. |
- | options.account | string | - | The account to associate with the PushAPI. If not provided, it is derived from signer. |
- | options.version | string | ENC_TYPE_V3 | The 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.autoUpgrade | boolean | true | If true , upgrades encryption keys to latest encryption version |
- | options.origin | string | - | Specify origin or source while creating a Push Profile |
Note: Parameters
in this style
are mandatory.
Expected response
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?: {
NFTPGP_V1?: {
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;
}
/**
* 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
}
Using for Lens / Cyberconnect / Any NFTs
Intermediate section, can be skipped unless you are planning to message NFT, .lens, .polygon or different blockchains.
Push Chat supports Lens, Cyberconnect, NFT wallets and any EVM or non-EVM wallets. Since address standards for all of these are different, we came up with a compatible standard that is chain agnostic to ensure cross-chain messaging or cross-nft messaging can become a reality.
This lead us to introduce support for multiple wallet address formats and coining the word account
instead of address
to be used in parameters wherever necessary.
Standard Wallet Address
- Standard Wallet Address - Standard wallet is supported and used by default
usage
-0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666
Chain Agnostic Wallet Address
- Chain Agnostic Wallet Address - Pass
{chain_standard}:{account_id}
format to use this instead of standard wallet address. SDK converts all normal wallet address to chain agnostic ones by default. usage
-eip155:0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666
usage
-cosmos:cosmos1t2uflqwqe0fsj0shcfkrvpukewcw40yjj6hdc0
usage
-starknet:0x02dd1b492765c064eac4039e3841aa5f382773b598097a40073bd8b48170ab57
Blockchain Agnostic Wallet Address has been inspired by CAIP-10 standard, which is a great step in marking wallet address blockchain agnostic.
Lens profile / Cyberconnect profile / NFT profile
- NFT profile - Pass
nft:{chain_standard}:{nftChainId}:{nftContractAddress}:{nftTokenId}
usage
-nft:eip155:11155111:0x42af3147f17239341477113484752D5D3dda997B:2:1683058528