Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(/packages/examples/token-gated-chat): added token gated chat exa… #791

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/examples/token-gated-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# About Token Gated Chat
Token gated chat shows you how to create group chats using Push Chat that can gated in various ways including token or NFT gating on entry of the group or when a participant of that group wants to send a message

## What's the use case
You can use this example to see the functionality of token gating. Some use cases are:

- Creating your token gated community and hosting that particular chat on your frontend
- Enabling more token use cases and ensuring that conversations that happen in your group are coming from token holders or from participants that have certain on-chain traits (for example: POAPs, ENS domain names, UD domain names, tec)

## Install instructions
1. Navigate to this directory from the terminal
2. do `npm install` or `yarn install`
3. do `yarn start`
59 changes: 59 additions & 0 deletions packages/examples/token-gated-chat/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PushAPI } from '@pushprotocol/restapi';
import { ethers } from 'ethers';

// Creating a random signer from a wallet, ideally this is the wallet you will connect
const signer = ethers.Wallet.createRandom();

console.log(`Signer address: ${signer.address} | Signer private key: ${signer.privateKey}`);

// Initialize wallet user, pass 'prod' instead of 'staging' for mainnet apps
const userAlice = await PushAPI.initialize(signer, { env: 'staging' });

// Creating your token gated community
const createTokenGatedGroup = await userAlice.chat.group.create('Push Community', {
description: 'Token gated web3 native chat example', // provide short description of group
image: 'data:image/png;base64,iVBORw0K...', // provide base64 encoded image
members: [], // not needed, rules define this, can omit
admins: [], // not needed as per problem statement, can omit
private: true,
rules: {
"entry": { // entry is based on conditions
"conditions": {
"any": [ // any of the decider should allow entry
{ // decider 1 - If admin or owner invites someone
"any": [
{ // criteria 1
"type": "PUSH",
"category": "INVITE",
"subcategory": "DEFAULT",
"data": {
"inviterRoles": [
"ADMIN",
"OWNER"
]
}
}
]
},
{ // decicder 2 - If wallet holds 1 NFT on polygon testnet
"any": [
{ // criteria 1
type: "PUSH", // define type that rules engine should go for
category: "ERC721", // define it's ERC20 token that you want to check, supports ERC721 as well
subcategory: "holder", // define if you are checking 'holder'
data: {
"contract": "eip155:80001:0x9105D95577575116948F5afcF479254f49F27939",
"comparison": ">=", // what comparison needs to pass
"amount": 1, // amount that needs to passed
"decimals": 18,
}
}
]
}
]
}
}
}
});

console.log("Chat created successfully!", createTokenGatedGroup);
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "automated-chat",
"name": "token-gated-chat",
"version": "1.0.0",
"description": "Example of Push Chat from backend, auto-responding to messages sent",
"main": "src/index.js",
"description": "Example of Push Chat token gated group in action",
"main": "index.js",
"type": "module",
"scripts": {
"build": "rimraf ./build && tsc",
"start": "nodemon",
"inspect": "nodemon --inspect src/index.js",
"dev": "node-dev --respawn --transpile-only src/index.js",
"inspect": "nodemon --inspect index.js",
"dev": "node-dev --respawn --transpile-only index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@pushprotocol/restapi": "1.4.19",
"@pushprotocol/restapi": "latest",
"@pushprotocol/socket": "0.5.2",
"ethers": "5.7.2"
},
Expand Down
Empty file.
42 changes: 0 additions & 42 deletions packages/examples/use-cases/automated-chat/src/index.js

This file was deleted.

Loading