leaderboards.topRevenue()
Get feeds ranked by total revenue generated within a specified time period.
Signature
leaderboards.topRevenue(query?: LeaderboardPeriodQuery): Promise<LeaderboardResponse<TopRevenueFeed>>Parameters
query (optional)
- Type:
LeaderboardPeriodQuery
interface LeaderboardPeriodQuery {
page_size?: number; // Results per page (default: 20)
period?: '1d' | '7d' | '30d' | 'all'; // Time period (default: 'all')
}Returns
- Type:
Promise<LeaderboardResponse<TopRevenueFeed>>
interface TopRevenueFeed {
rank: string;
feed_id: string;
feed_name: string;
owner_id: string;
owner_username?: string | null;
owner_wallet: string;
category_id?: string | null;
category_name: string;
description?: string | null;
image_cid?: string | null;
is_active: boolean;
tags?: string[] | null;
total_entries: number;
total_purchases: string;
total_revenue: string;
unique_buyers: string;
feed_created_at: number;
feed_updated_at: number;
}Usage
Basic Example
const topRevenue = await grapevine.leaderboards.topRevenue();
topRevenue.data.forEach(feed => {
console.log(`#${feed.rank}: ${feed.feed_name}`);
console.log(` Revenue: ${formatUSDC(feed.total_revenue)}`);
console.log(` Purchases: ${feed.total_purchases}`);
});
function formatUSDC(weiAmount: string): string {
const usdc = Number(BigInt(weiAmount)) / 1e6;
return `${usdc.toLocaleString('en-US', { minimumFractionDigits: 2 })}`;
}Filter by Period
// Top revenue feeds this month
const monthlyTop = await grapevine.leaderboards.topRevenue({
period: '30d',
page_size: 10
});
console.log('Top earners this month:');
monthlyTop.data.forEach((feed, i) => {
console.log(`${i + 1}. ${feed.feed_name}: ${formatUSDC(feed.total_revenue)}`);
});Revenue Analytics
async function getRevenueAnalytics() {
const topFeeds = await grapevine.leaderboards.topRevenue({ page_size: 100 });
// Calculate total platform revenue
const totalRevenue = topFeeds.data.reduce(
(sum, feed) => sum + BigInt(feed.total_revenue),
BigInt(0)
);
// Calculate average revenue per feed
const avgRevenue = totalRevenue / BigInt(topFeeds.data.length);
// Find revenue distribution
const distribution = {
over1000: topFeeds.data.filter(f => BigInt(f.total_revenue) > BigInt(1000_000_000)).length,
over100: topFeeds.data.filter(f => BigInt(f.total_revenue) > BigInt(100_000_000)).length,
over10: topFeeds.data.filter(f => BigInt(f.total_revenue) > BigInt(10_000_000)).length
};
return {
totalRevenue: formatUSDC(totalRevenue.toString()),
avgRevenue: formatUSDC(avgRevenue.toString()),
distribution
};
}Leaderboard Display
function RevenueLeaderboard({ period }: { period?: LeaderboardPeriod }) {
const [feeds, setFeeds] = useState<TopRevenueFeed[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
setLoading(true);
grapevine.leaderboards.topRevenue({ period, page_size: 10 })
.then(result => {
setFeeds(result.data);
setLoading(false);
});
}, [period]);
if (loading) return <div>Loading...</div>;
return (
<div className="leaderboard">
<h2>Top Revenue Feeds</h2>
<table>
<thead>
<tr>
<th>Rank</th>
<th>Feed</th>
<th>Creator</th>
<th>Revenue</th>
<th>Purchases</th>
</tr>
</thead>
<tbody>
{feeds.map(feed => (
<tr key={feed.feed_id}>
<td className="rank">#{feed.rank}</td>
<td>
<strong>{feed.feed_name}</strong>
{feed.category_name && (
<span className="category">{feed.category_name}</span>
)}
</td>
<td>{feed.owner_username || feed.owner_wallet.slice(0, 8)}...</td>
<td className="revenue">{formatUSDC(feed.total_revenue)}</td>
<td>{feed.total_purchases}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}Notes
- Authentication: Not required - public endpoint
- Ranking: Ordered by total revenue (highest first)
- Currency: Revenue amounts are in wei (USDC has 6 decimals)
Related
- leaderboards.topProviders() - Top creators by revenue
- leaderboards.mostPopular() - By purchase count
- wallets.getStats() - Individual wallet stats