Follow Revenues

Learn how to retrieve revenue from follows.


As discussed in the Follow and Unfollow section, you can configure a Lens Profile to charge users a fee when they choose to follow it.

This page will guide you on how to retrieve the follow revenues associated with your Lens Profile.

You can use the useRevenueFromFollow hook to retrieve the follow revenue associated with a Lens Profile.

Available in @lens-protocol/react-web and @lens-protocol/react-native

import {  Amount,  Asset,  erc20Amount,  Erc20Amount,  fiatAmount,  FiatAmount,  Profile,  RevenueAggregate,  useRevenueFromFollow,} from '@lens-protocol/react-web';
function Revenue({ profile }: { profile: Profile }) {  const { data, loading, error } = useRevenueFromFollow({    for: profile.id,  });
  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error: {error.message}</p>;
  return (    <div>      {data.length ? (        data.map((revenue, index) => <RevenueCard key={index} revenue={revenue} />)      ) : (        <p>No revenue.</p>      )}    </div>  );}
function RevenueCard({ revenue }: { revenue: RevenueAggregate }) {  const erc20 = erc20Amount(revenue.total);  const rate = revenue.total.rate ? fiatAmount(revenue.total.rate) : null;
  return (    <div>      <p>{`Currency: ${erc20.asset.name}`}</p>      <p>{`Value: ${formatAmount(erc20)}`}</p>      {rate && <p>{`Fiat value: ${formatFiatAmount(erc20, rate)}`}</p>}    </div>  );}
function formatAmount(amount: Amount<Asset>): string {  return `${amount.toSignificantDigits()} ${amount.asset.symbol}`;}
function formatFiatAmount(amount: Erc20Amount, rate: FiatAmount): string {  const fiat = amount.convert(rate);  return formatAmount(fiat);}

Note that we use erc20Amount and fiatAmount helpers to convert the amounts returned from the API into objects. These objects provide useful methods for comparing and formatting the amounts.

That's it—you now understand how to retrieve the follow revenues associated with your Lens Profile.