← Protocols
Lens Protocol
01Description

Onchain social graph with portable profiles, follows, posts, and groups. Lens v3 runs on Lens Chain (a ZK-stack L2) and exposes a GraphQL API plus a typed client SDK.

02Best for
  • 01portable social profiles
  • 02onchain follow / post graphs
  • 03tokenised content / collects
  • 04creator monetisation
  • 05social-native dapps
03Install
  • pnpm add @lens-protocol/client @lens-chain/sdk viem
  • pnpm add @lens-protocol/react # optional React bindings
04Environment variables
VariableScopeDescription
NEXT_PUBLIC_LENS_APP_ADDRESSClientAddress of the Lens v3 App contract you registered for your dapp. Required for authentication and post attribution.
NEXT_PUBLIC_LENS_ENVIRONMENTClientLens environment: 'mainnet' (Lens Chain) or 'testnet'.
05Prompt snippet
Use Lens v3 for onchain social. Create a client with `const client = PublicClient.create({ environment: mainnet, origin: 'https://yourapp.com' })` from `@lens-protocol/client`. Authenticate users via `client.login({ accountOwner: { account, app: NEXT_PUBLIC_LENS_APP_ADDRESS, owner } }, signMessage)`, returning a `SessionClient`. Read with actions like `fetchPosts`, `fetchAccount`, `fetchFollowers` from `@lens-protocol/client/actions`. Publish via `post(sessionClient, { contentUri })` where `contentUri` points to Lens-compatible metadata JSON on Grove / IPFS. Submit the returned transaction with `handleOperationWith(walletClient)` from `@lens-chain/sdk/viem`.
06Gotchas
  • Lens v3 lives on Lens Chain, not Ethereum or Polygon — users need Lens Chain ETH for gas (or use the Sponsorship contract to gasless-relay).
  • v2 (Polygon) and v3 (Lens Chain) are separate networks with different contracts and APIs — pick one and do not mix the SDKs.
  • Posts reference a Grove / IPFS metadata URI that must conform to the Lens metadata standard; malformed JSON will be rejected at publish time.
  • Every dapp must register an App contract on-chain — posts created without an `app` field will not show up in app-scoped feeds.
  • Authentication tokens are short-lived (~30 min) and need silent refresh via `client.resumeSession()`.
  • Account abstraction: Lens accounts are smart contracts owned by an EOA; signature flows must use EIP-1271 verification.
07Alternatives