Edit a Post
This guide explains how to edit a Post content on Lens.
To update a Post on Lens, follow these steps:
Create a new Post Metadata object.
Upload this object to a publicly accessible URI.
Update the Post with the new Metadata object.
See the Lens Metadata Standards guide for more information on creating and hosting Metadata objects.
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!`,});
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.
You MUST be authenticated as Account Owner or Account Manager to make this request.
- TypeScript
- GraphQL
- React
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);}
- 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.