Help & Support

Delete a Post

This guide will help you delete a post from a Lens Feed.

To delete a Post on Lens, follow these steps.

You MUST be authenticated as Account Owner or Account Manager for the post your are trying to delete.

1

Check Post Rules

First, inspect the post.operations.canDelete field to determine whether the logged-in Account is allowed to edit the Post. Some posts may have restrictions on who can

Check Rules
switch (post.operations.canDelete.__typename) {  case "PostOperationValidationPassed":    // Commenting is allowed    break;
  case "PostOperationValidationFailed":    // Commenting is not allowed    console.log(post.operations.canEdit.reason);    break;
  case "PostOperationValidationUnknown":    // Validation outcome is unknown    break;}

Where:

  • PostOperationValidationPassed: The logged-in Account is allowed delete the Post.

  • PostOperationValidationFailed: Deleting is not allowed. The reason field explains why, and unsatisfiedRules lists the unmet requirements.

  • PostOperationValidationUnknown: The Post or its Feed (for custom Feeds) has one or more unknown rules requiring ad-hoc verification. The extraChecksRequired field provides the addresses and configurations of these rules.

Treat the PostOperationValidationUnknown as failed unless you intend to support the specific rules. See Post Rules for more information.

2

Delete the Post

Next, if allowed, delete the Post.

Bear in mind that the trail of the Post existance will remain as part of the blockchain history.

Use the deletePost action to submit/create a delete transaction.

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

3

Handle Result

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

import { handleOperationWith } from "@lens-protocol/client/viem";
// …
const result = await deletePost(sessionClient, {  post: postId("01234…"),}).andThen(handleOperationWith(walletClient));

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

4

Delete the Content

Finally, to delete a Post's content, you must remove the Post Metadata object located at post.contentURI, along with any referenced files.

The deletion process depends on the hosting solution used when the Post was created or last updated. For example, if IPFS was used, you should unpin the content to free up resources.

If you used Lens Storage Nodes, the result of the first step will determine your next steps:

  • If you received a DeletePostResponse, the Lens API has already handled the content deletion for you, and no further action is required.

  • If you received a SponsoredTransactionRequest or SelfFundedTransactionRequest, you will need to delete the content by calling the lens storage nodes. See the Deleting Content guide for more information.