-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(/packages/examples/token-gated-chat): added token gated chat exa… (
#791) * docs(/packages/examples/token-gated-chat): added token gated chat example * docs(/packages/examples/token-gated-chat/readme.md): added relevant readme file
- Loading branch information
1 parent
072dc88
commit 325ad80
Showing
6 changed files
with
78 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
File renamed without changes.
12 changes: 6 additions & 6 deletions
12
...les/use-cases/automated-chat/package.json → ...es/examples/token-gated-chat/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.