Getting Started
This guide will help you get started with the Lens API and SDKs.
React SDK
The Lens React SDK is a collection of React Hooks for both web and React Native applications. It's the simplest way to interact with the Lens API and build decentralized applications on Lens Network.
The Lens React SDK is currently in development and will be released soon.
TypeScript SDK
The Lens TypeScript SDK is a low-level API client for interacting with the Lens API. It provides a lightweight abstraction over the bare GraphQL API and is suitable for server-to-server communication or very bespoke client-side integrations where the Lens React SDK is not suitable.
The Lens TypeScript SDK adopts a modular, functional approach to interacting with the Lens API, inspired by the viem client-actions architecture. It organizes functionality into distinct, reusable actions, each tailored to a specific API feature.
Create an instance of the PublicClient pointing to the desired environment.
client.ts
import { PublicClient, testnet } from "@lens-protocol/client";
export const client = PublicClient.create({ environment: testnet, origin: "https://myappdomain.xyz", // Ignored if running in a browser});
That's it—you can now use the @lens-protocol/client/actions to interact with the Lens API.
GraphQL API
The Lens API utilizes GraphQL, a query language for APIs that allows clients to precisely request the data they need, leading to more efficient data retrieval. GraphQL queries are executed using a type system defined for your data. It is written in rust so it is blazing fast.
Environments
The API links below act as API endpoints as well as playgrounds for testing queries.
Network | URL | |
---|---|---|
Lens API Testnet | https://api.testnet.lens.dev/graphql | |
Lens API Mainnet | Coming soon |
GraphQL Clients
Below are examples of how to interact with the Lens API using different GraphQL clients.
- URQL
- Apollo Client
- Fetch API
The URQL client is a lightweight and flexible GraphQL client that can be used in both web and mobile applications.
urql.ts
import { gql, Client, cacheExchange, fetchExchange } from "urql";
const ENDPOINT = "https://api.testnet.lens.dev/graphql";
const client = new Client({ url: ENDPOINT, exchanges: [cacheExchange, fetchExchange],});
const result = await client.query(gql` query { posts(request: { pageSize: TEN }) { items { id author { username { value } } metadata { ... on TextOnlyMetadata { content } } } pageInfo { prev next } } }`);
console.log(result);