Custom Feeds
This guide will introduce the concept of Custom Feeds and how to create and manage them.
As mentioned in the Feed concept page, there are two classes of Feed instances:
The Global Feed: The familiar shared feed that aggregates all public Lens activity.
Custom Feeds: App or group-specific feeds that can be open or governed by Feed Rules.
Create a Custom Feed
To create a Custom Feed, follow these steps.
You MUST be authenticated as Builder to create a Feed.
First, construct a Feed Metadata object with the necessary content.
- TS/JS
- JSON Schema
Use the @lens-protocol/metadata package to construct a valid FeedMetadata object:
Example
import { feed } from "@lens-protocol/metadata";
const metadata = feed({ name: "XYZ", description: "My custom feed description",});
Next, upload the Feed Metadata object to a public URI.
import { storageClient } from "./storage-client";
const { uri } = await storageClient.uploadAsJson(metadata);
console.log(uri); // e.g., lens://4f91ca…
This example uses Grove storage to host the Metadata object. See the Lens Metadata Standards guide for more information on hosting Metadata objects.
Next, deploy the Lens Feed smart contract.
- TypeScript
- GraphQL
- React
Use the createFeed action to deploy the Lens Feed smart contract.
To learn more about how to use Feed Rules, see the Feed Rules guide.
- TypeScript
- GraphQL
- React
Next, handle the result using the adapter for the library of your choice and wait for it to be indexed.
See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.
- TypeScript
- GraphQL
Finally, fetch the newly created Feed using the fetchFeed action.
viem
import { fetchFeed } from "@lens-protocol/client/actions";
// …
const result = await createFeed(sessionClient, { metadataUri: uri("lens://4f91…"), // the URI from the previous step}) .andThen(handleOperationWith(walletClientOrSigner)) .andThen(sessionClient.waitForTransaction) .andThen((txHash) => fetchFeed(sessionClient, { txHash }));
if (result.isErr()) { return console.error(result.error);}
// feed: Feed | nullconst feed = result.value;
Fetch a Feed
- TypeScript
- GraphQL
- React
Use the fetchFeed action to fetch a single Feed by address or by transaction hash.
Search Feeds
- TypeScript
- GraphQL
- React
Use the paginated fetchFeeds action to search for feeds.
Continue with the Pagination guide for more information on how to handle paginated results.
Update Feed Metadata
To update a Feed Metadata, follow these steps.
You MUST be authenticated as Builder, Account Manager, or Account Owner and be either the owner or an admin of the Feed you intend to update.
First, create a new Feed Metadata object with the updated details.
It's developer responsibility to copy over any existing data that should be retained.
The process is similar to the one in the Create a Feed guide, so we will keep this example brief.
Example
import { feed } from "@lens-protocol/metadata";
const metadata = feed({ name: "XYZ", description: "My feed description",});
Next, upload the Feed Metadata object to a public URI.
Upload Metadata
import { storageClient } from "./storage-client";
// …
const { uri } = await storageClient.uploadAsJson(metadata);
console.log(uri); // e.g., lens://4f91ca…
If Grove storage was used you can also decide to edit the file at the existing URI. See Editing Content guide for more information.
Next, update the Feed metadata URI with the new URI.
- TypeScript
- GraphQL
- React
Use the setFeedMetadata action to update the Feed Metadata URI.
import { uri } from "@lens-protocol/client";import { setFeedMetadata } from "@lens-protocol/client/actions";
const result = await setFeedMetadata(sessionClient, { feed: feed.address, metadataUri: uri("lens://4f91ca…"),});
if (result.isErr()) { return console.error(result.error);}
- TypeScript
- GraphQL
- React
Finally, handle the result using the adapter for the library of your choice:
See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.
Access Control
The Feed contract supports two roles: Owner and Administrator.
Administrators can:
Update the Feed Metadata
Update the Feed Rules
Update the Feed Extra Data
The Owner can do everything the administrators can do, plus transfer ownership of the Feed to another address.
See the Team Management guide for more information on how to manage these roles.