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:
Create the Post Metadata object.
Upload this object to a publicly accessible URI.
Use this metadata URI to create the Lens Post.
See the Lens Metadata Standards guide for more information on creating and hosting Metadata objects.
First, construct a Post Metadata object with the necessary content.
- TS/JS
- JSON Schema
The Post Metadata Standard encompass various types of content. Below is a list of the most common ones.
- Text-Only
- Audio
- Image
- Video
- Article
- Others
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.
Then, upload the Post Metadata object to a public 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…
This example uses Lens Storage to host the Metadata object. See the Lens Metadata Standards guide for more information on hosting Metadata objects.
- TypeScript
- GraphQL
- React
You MUST be authenticated as Account Owner or Account Manager to make this request.
Then, use the post action to create a Lens Post.
import { post } from "@lens-protocol/client/actions";
See below examples for creating a Post, Comment, and Quote.
- TypeScript
- GraphQL
- React
Finally, handle the result using the adapter for the library of your choice:
The Lens SDK example here leverages a functional approach to chaining operations using the Result<T, E> object. See the Error Handling guide for more information.
See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.
Post Rules
Coming soon.
Post Actions
Coming soon.