Install
yarn add epns-sdk
Use
import {Query, ChannelSubscription} from 'epns-sdk'
import * as ethers from 'ethers'
;(async () => {
const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/vbstreetz/epns'
const ROPSTEN_CONTRACT_ADDRESS = '0xb02E99b9634bD21A8e3E36cc7adb673287A8FeaC'
const CHANNEL_ADDRESS = '0x..channel..address'
const query = new Query(SUBGRAPH_URL)
console.log(await query.getChannels())
const channel = await query.getChannel(CHANNEL_ADDRESS)
const provider = new ethers.providers.Web3Provider(window.ethereum)
const channelSubscription = new ChannelSubscription(
ROPSTEN_CONTRACT_ADDRESS,
provider.getSigner(), CHANNEL_ADDRESS
)
console.log('subscribed to %s: %s', (channel.name, await channelSubscription.getIsSubscribed())
channelSubscription.onChange(subscribed => console.log({subscribed}))
button.onclick = () => await channel.toggle()
})()
The SDK provides the following clients:
- Query: ran queries against an EPNS subgraph.
- ChannelSubscription: subscribe and/ manage the subscription to a channel.
- ChannelOwner: send out channel notifications, get stats etc.
- Channels: subscribe to channel creations + updates.
- Notifications: subscribe to notifications.
Make a new Query
client to use to run queries against an EPNS subgraph at subGraphUrl
.
Get a list of channels.
To get all channels, invoke: query.getChannels()
.
To retrieve a paginated list of channels, pass in the page
and count
query parameters, e.g. query.getChannels(1, 3)
.
Get channel info for channelAddress
.
Get a list of a userAddress
's notifications.
Pass in the optional page
and count
to get a paginated list of the notifications.
Fetch notification info matching id
.
Get whether userAddress
is subscribed to channelAddress
.
Execute a query
(with variables
) against subgraphUrl
.
Make a new ChannelSubscription
client for signer
and channelAddress
at contractAddress
.
Subscribe to channel.
Cancel subscription.
Toggle subscription state of the user.
Get whether user address is subscribed to channel.
Subscribe to changes in the subscription state of user address and invoke fn(subscribed: boolean)
.
Returns a function to stop listening to the changes.
Make a new ChannelOwner
client to manage the channel owned by signer
.
Get detailed channel stats as an owner.
channelOwner.notify(type: string, msg: string, recipientAddress?: string, sub?: string, cta?: string, img?: string): Promise<ethers.Transaction>
Send out a notification.
Make a new Channels
client to subscribe to channel events.
Invoke fn
whenever a new channel is added.
Returns a function to cancel listening to new channel additions.
Make a new Notifications
client to subscribe to notifications sent to signer
.
Invoke fn
for every notification sent to signer
.
Returns a function to cancel listening to new notifications.
MIT