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.

Upload
import { textOnly } from "@lens-protocol/metadata";import { uploadJson } from "./my-upload-lib";
const metadata = textOnly({  content: `GM! GM!`,});
const contentUri = await uploadJson(metadata); // e.g., lens://4f91ca…

If Lens Storage Nodes was used you can edit or delete content as needed. See the Editing Content and Deleting Content guides for more information.

3

Update Post Content URI

Then, you can use the editPost mutation to update the Post content URI.

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

mutation {  editPost(request: { post: "42", contentUri: "lens://4f91ca…" }) {    ... on PostResponse {      hash    }
    ... on SponsoredTransactionRequest {      ...SponsoredTransactionRequest    }
    ... on SelfFundedTransactionRequest {      ...SelfFundedTransactionRequest    }
    ... on TransactionWillFail {      reason    }  }}

Finally, handle the result as explained in the Transaction Lifecycle guide.