Create a Post

This guide will walk you through the process of creating a Post.


Your First Post

Lens Post content, including text, images, videos, and more, is stored in what's known as Post Metadata. This metadata is a JSON file linked to the Lens Post via its public URI.

To create a Post on Lens, follow these steps:

  1. Create the Post Metadata object.

  2. Upload this object to a publicly accessible URI.

  3. Use this metadata URI to create the Lens Post.

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

1

Create Post Metadata

First, construct a Post Metadata object with the necessary content.

The Post Metadata Standard encompass various types of content. Below is a list of the most common ones.

Used to describe content that is text-only, such as a message or a comment.

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

See textOnly(input): TextOnlyMetadata reference doc.

2

Upload Post Metadata

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

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…

3

Submit On-Chain

Then, you can use the post mutation to create a Lens Post.

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

See below examples for creating a Post, Comment, and Quote.

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

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

Post Rules

Coming soon.

Post Actions

Coming soon.