Help & Support

Create a Group

This guide will help you create a Group on Lens.

To create an Group, follow these steps.

You MUST be authenticated as Builder, Account Manager, or Account Owner to create a Group.

1

Create Group Metadata

First, construct a Group Metadata object.

Use the @lens-protocol/metadata package to construct a valid GroupMetadata object:

Example
import { group } from "@lens-protocol/metadata";
const metadata = group({  name: "XYZ",  description: "My group description",  icon: "lens://BsdfA…",});

2

Upload Group Metadata

Next, upload the Group 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.

3

Deploy Group Contract

Next, deploy the Group smart contract.

Use the createGroup action to deploy the Lens Group smart contract.

import { uri } from "@lens-protocol/client";import { createGroup } from "@lens-protocol/client/actions";
const result = await createGroup(sessionClient, {  metadataUri: uri("lens://4f91c…"),});

To learn more about how to use Group Rules, see the Group Rules guide.

4

Handle Result

Next, handle the result using the adapter for the library of your choice and wait for it to be indexed.

import { handleOperationWith } from "@lens-protocol/client/viem";
// …
const result = await createGroup(sessionClient, {  metadataUri: uri("lens://4f91ca…"),})  .andThen(handleOperationWith(walletClient))  .andThen(sessionClient.waitForTransaction);

See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.

5

Fetch New Group

Finally, fetch the newly created Group using the fetchGroup action.

viem
import { fetchGroup } from "@lens-protocol/client/actions";
// …
const result = await createGroup(sessionClient, {  metadataUri: uri("lens://4f91…"), // the URI from the previous step})  .andThen(handleOperationWith(walletClientOrSigner))  .andThen(sessionClient.waitForTransaction)  .andThen((txHash) => fetchGroup(sessionClient, { txHash }));
if (result.isErr()) {  return console.error(result.error);}
// group: Group | nullconst group = result.value;

That's it—you have successfully created a Group on Lens!