Skip to main content

How to Get Channel Subscribers and Stakes

The getChannelSubscribersAndStakes endpoint allows you to retrieve the list of subscribers and stakers for a specific channel. This guide will walk you through how to use this endpoint and paginate through the results.

Endpoint

GET https://www.alfafrens.com/api/v0/getChannelSubscribersAndStakes?channelAddress={channelAddress}&first={first}&skip={skip}

Parameters

  • channelAddress: The address of the channel you want to retrieve data for.
  • first: The number of results to return (default is 10).
  • skip: The number of results to skip (useful for pagination).

Example Request

To retrieve the first 10 subscribers and stakers for a channel with the address 0x0ea5c1755a38b5bd28826cca5afc88d530551eeb, you would use the following request:

GET https://www.alfafrens.com/api/v0/getChannelSubscribersAndStakes?channelAddress=0x0ea5c1755a38b5bd28826cca5afc88d530551eeb&first=10&skip=0

Example Response

The response from this endpoint includes information about the subscribers and stakers, such as their IDs, subscription and stake statuses, and other related data. Here is an example of what the response looks like:

{
"id": "0x0ea5c1755a38b5bd28826cca5afc88d530551eeb",
"numberOfSubscribers": 587,
"numberOfStakers": 183,
"totalSubscriptionFlowRate": "111681887366818569",
"totalSubscriptionInflowAmount": "249838004946726867909198",
"totalClaimed": "6846280730140571067",
"owner": "0xb431aa4d612b10f571b0c6d1ba47de7dca50c850",
"currentStaked": "3533005164380157618",
"members": [
{
"id": "0x0ea5c1755a38b5bd28826cca5afc88d530551eeb0028473fb3243fa3fb61511c99e91344a88d8d87",
"lastUpdatedTimestamp": "1714860163",
"subscriber": {
"id": "0x0028473fb3243fa3fb61511c99e91344a88d8d87"
},
"channel": {
"id": "0x0ea5c1755a38b5bd28826cca5afc88d530551eeb",
"owner": "0xb431aa4d612b10f571b0c6d1ba47de7dca50c850"
},
"isSubscribed": false,
"isStaked": false,
"currentStaked": "0",
"totalSubscriptionOutflowRate": "0",
"totalSubscriptionOutflowAmount": "984779299847790312",
"estimatedTotalCashbackFlowRate": "0",
"estimatedTotalCashbackAmount": "0",
"fid": "441498"
},
...
],
"title": "Youssef 🫂🎩",
"bio": "DevRel & Frames @superfluid / Sign up to 🫂: @alfafrens",
"hasMore": true
}

Retrieving Subscribers and Stakers

Subscribers

Subscribers can be identified by the isSubscribed field being true. To get a list of all subscribers, you can filter the members array:

const subscribers = response.members.filter(member => member.isSubscribed);

Stakers

Stakers can be identified by the isStaked field being true. To get a list of all stakers, you can filter the members array:

const stakers = response.members.filter(member => member.isStaked);

Pagination

To paginate through the results, you can use the first and skip parameters. For example, to get the next 10 results, you would set skip to 10:

GET https://www.alfafrens.com/api/v0/getChannelSubscribersAndStakes?channelAddress=0x0ea5c1755a38b5bd28826cca5afc88d530551eeb&first=10&skip=10

You can continue incrementing the skip value by the first value to get subsequent pages.

Example Code

JavaScript

Here is an example of how you might retrieve and process the data in JavaScript:

async function getSubscribersAndStakers(channelAddress, first = 10, skip = 0) {
const response = await fetch(`https://www.alfafrens.com/api/v0/getChannelSubscribersAndStakes?channelAddress=${channelAddress}&first=${first}&skip=${skip}`);
const data = await response.json();

const subscribers = data.members.filter(member => member.isSubscribed);
const stakers = data.members.filter(member => member.isStaked);

return { subscribers, stakers, hasMore: data.hasMore };
}

const channelAddress = '0x0ea5c1755a38b5bd28826cca5afc88d530551eeb';
const first = 10;
let skip = 0;
let hasMore = true;

while (hasMore) {
const { subscribers, stakers, hasMore: more } = await getSubscribersAndStakers(channelAddress, first, skip);
console.log('Subscribers:', subscribers);
console.log('Stakers:', stakers);
skip += first;
hasMore = more;
}

This code fetches the subscribers and stakers for the specified channel address and handles pagination to retrieve all the results.

Further Information

For more details on the API, including additional usage examples and response formats, please refer to the full API documentation or head to our Discord channel #dev-support for assistance.


Happy coding with AlfaFrens API!