Help & Support

Edit a Post

This guide explains how to edit a Post content on Lens.

To update a Post on Lens, follow these steps:

  1. Create a new Post Metadata object.

  2. Upload this object to a publicly accessible URI.

  3. Update the Post with the new Metadata object.

See the Lens Metadata Standards guide for more information on creating and hosting Metadata objects.

1

Create Post Metadata

First, create a new Post Metadata object with the updated details.

It's developer responsability to copy over any existing data that should be retained.

The process is similar to the one in the Create a Post guide, so we will keep this example brief.

Text-only
import { textOnly } from "@lens-protocol/metadata";
const metadata = textOnly({  content: `GM! GM!`,});

2

Upload Metadata

Next, upload the Post Metadata object to a public URI.

If the hosting solution used when the Post was created or last updated allows edits, you may want to choose between:

  • Keeping a history of the file, like a document revision, by uploading it to a new URI.

  • Erasing the previous version by updating the content at the same URI.

import { textOnly } from "@lens-protocol/metadata";import { storageClient } from "./storage-client";
const metadata = textOnly({  content: `GM! GM!`,});
const { uri } = await storageClient.uploadAsJson(metadata);
console.log(uri); // e.g., lens://4f91ca…

If Lens Storage Nodes was used you can decide if also metadata can be edited and delete as needed. See the Editing Content and Deleting Content guides for more information.

3

Update Post Content URI

You MUST be authenticated as Account Owner or Account Manager to make this request.

Use the editPost action to update the Post content URI.

import { postId, uri } from "@lens-protocol/client";import { editPost } from "@lens-protocol/client/actions";
const result = await editPost(sessionClient, {  contentUri: uri("lens://4f91ca…"),  post: postId("01234…"),});
if (result.isErr()) {  return console.error(result.error);}

4

Handle Result

Finally, handle the result using the adapter for the library of your choice:

import { handleWith } from "@lens-protocol/client/viem";
// …
const result = await editPost(sessionClient, {  contentUri: uri("lens://4f91ca…"),  post: postId("01234…"),}).andThen(handleWith(walletClient));

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