{"id":13767255,"url":"https://github.com/memester-xyz/lens-use","last_synced_at":"2025-05-10T22:31:38.696Z","repository":{"id":62606954,"uuid":"560797106","full_name":"memester-xyz/lens-use","owner":"memester-xyz","description":"React hooks for Lens Protocol","archived":false,"fork":false,"pushed_at":"2023-01-10T22:43:18.000Z","size":617,"stargazers_count":94,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-17T02:34:29.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/memester-xyz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-02T09:39:38.000Z","updated_at":"2024-02-02T17:43:19.000Z","dependencies_parsed_at":"2023-02-08T20:31:52.281Z","dependency_job_id":null,"html_url":"https://github.com/memester-xyz/lens-use","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memester-xyz%2Flens-use","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memester-xyz%2Flens-use/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memester-xyz%2Flens-use/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/memester-xyz%2Flens-use/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/memester-xyz","download_url":"https://codeload.github.com/memester-xyz/lens-use/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253492529,"owners_count":21916959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T16:01:06.710Z","updated_at":"2025-05-10T22:31:36.750Z","avatar_url":"https://github.com/memester-xyz.png","language":"TypeScript","funding_links":[],"categories":["Development"],"sub_categories":["Libraries \u0026 Tools"],"readme":"\u003ch1 align=\"center\"\u003elens-use 🌱\u003c/h1\u003e\n\n\u003ch2 align=\"center\"\u003eDeprecation Notice\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n  Lens Protocol is working on their own \u003ca href=\"https://github.com/lens-protocol/lens-sdk\"\u003eReact SDK\u003c/a\u003e which should be used instead of this library.\n\u003c/p\u003e\n\n\u003ch2 align=\"center\"\u003eReact Hooks for Lens Protocol\u003c/h2\u003e\n\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://reactjs.org/\"\u003eReact\u003c/a\u003e 🤝 \u003ca href=\"https://www.lens.xyz/\"\u003eLens Protocol\u003c/a\u003e\n\u003c/p\u003e\n\n**Standing on the shoulders of these chads (aka, dependencies):**\n\n- [Apollo GraphQL](https://www.apollographql.com/docs/)\n- [wagmi](https://wagmi.sh/)\n- [ethers](https://docs.ethers.io/v5/)\n\n**Jump straight to the [Hooks Reference](#hooks-reference)**\n\n# Example\n\n```typescript\nconst { data: profileResponse } = useProfile(\"stani.lens\");\n\nconst { data: publicationsResponse } = usePublications(profileResponse?.profile?.id);\n\nconst { collect } = useCollect(publicationsResponse?.publications?.items[0].id);\n\nconst onClick = () =\u003e {\n  collect();\n};\n```\n\n# Installation\n\n```bash\n# npm\nnpm install --save @memester-xyz/lens-use\n\n# yarn\nyarn add @memester-xyz/lens-use\n\n# pnpm\npnpm add @memester-xyz/lens-use\n```\n\n# Usage\n\n## Basic\n\n1. Your app must first be wrapped in a Wagmi context and a Apollo context (connected to the Lens API). e.g.:\n\n```typescript\nfunction App() {\n  return (\n    \u003cWagmiConfig client={client}\u003e\n      \u003cApolloProvider client={apolloClient}\u003e\n        \u003cDApp /\u003e\n      \u003c/ApolloProvider\u003e\n    \u003c/WagmiConfig\u003e\n  );\n}\n```\n\n2. You can then use the Lens hooks in any components inside of your DApp component:\n\n```typescript\nimport { useProfile } from \"@memester-xyz/lens-use\";\n\n// ...\n\nconst { data } = useProfile(\"stani.lens\");\n```\n\n3. The return value of any API hook (e.g. `useProfile`, `useChallenge`) is a typed Apollo GraphQL return value. i.e.\n\n   - [`QueryResult`](https://www.apollographql.com/docs/react/api/react/hooks/#result) for queries\n   - [`MutationTuple`](https://www.apollographql.com/docs/react/api/react/hooks/#mutationtupletdata-tvariables-result-tuple) for mutations.\n\n4. The return value of any contract hook (e.g. `useContractProfile`, `useContractCollect`) is a modification of a normal Wagmi [`useContractRead`](https://wagmi.sh/docs/hooks/useContractRead#return-value) or [`useContractWrite`](https://wagmi.sh/docs/hooks/useContractWrite#return-value).\n\n5. The return value of any action hook (e.g. `useCollect`) is an object containing:\n   - a write method with the same name as the hook action (e.g. `collect()`)\n   - a loading boolean when the request is in flight `loading`\n   - an Error object or undefined `error`\n\nFull API specification is below in the [hooks](#hooks) section.\n\n## Advanced\n\nBy default we use the currently known Polygon Mainnet Lens Hub Proxy address. There are two ways to override this but both require adding our `LensProvider` context to your app.\n\n1. You can use the currently known Mumbai (testnet) address:\n\n```typescript\nfunction App() {\n  return (\n    \u003cWagmiConfig client={client}\u003e\n      \u003cApolloProvider client={apolloClient}\u003e\n        \u003cLensProvider network=\"testnet\"\u003e\n          \u003cDApp /\u003e\n        \u003c/LensProvider\u003e\n      \u003c/ApolloProvider\u003e\n    \u003c/WagmiConfig\u003e\n  );\n}\n```\n\n2. You can pass a custom Lens Hub contract address:\n\n```typescript\nfunction App() {\n  return (\n    \u003cWagmiConfig client={client}\u003e\n      \u003cApolloProvider client={apolloClient}\u003e\n        \u003cLensProvider lensHubAddress=\"0x...\"\u003e\n          \u003cDApp /\u003e\n        \u003c/LensProvider\u003e\n      \u003c/ApolloProvider\u003e\n    \u003c/WagmiConfig\u003e\n  );\n}\n```\n\n# Hooks Reference\n\n- [Login](#login)\n  - [useChallenge](#useChallenge)\n  - [useAuthenticate](#useAuthenticate)\n  - [useRefresh](#useRefresh)\n- [Query](#query)\n  - [useProfile](#useProfile)\n  - [useProfiles](#useProfiles)\n  - [useDefaultProfile](#useDefaultProfile)\n  - [useProfilePicture](#useProfilePicture)\n  - [useProfileHasDispatcher](#useProfileHasDispatcher)\n  - [usePublication](#usePublication)\n  - [usePublications](#usePublications)\n  - [usePublicationComments](#usePublicationComments)\n  - [useSearch](#useSearch)\n- [Write](#write)\n  - [useCollect](#useCollect)\n  - [useComment](#useComment)\n  - [useFollow](#useFollow)\n  - [useUnfollow](#useUnfollow)\n  - [useMirror](#useMirror)\n  - [usePost](#usePost)\n- [Contract](#contract)\n  - [useContractCollect](#useContractCollect)\n  - [useContractComment](#useContractComment)\n  - [useContractFollow](#useContractFollow)\n  - [useContractUnfollow](#useContractUnfollow)\n  - [useContractMirror](#useContractMirror)\n  - [useContractPost](#useContractPost)\n  - [useContractProfile](#useContractProfile)\n\n## Login\n\nHooks to help with authenticating against the Lens API.\n\n### useChallenge\n\n_[Lens Reference](https://docs.lens.xyz/docs/login#challenge)_\n\nGet a challenge to be signed by the user\n\n```typescript\nconst { data: challengeData } = useChallenge(address);\n\n// challengeData.challenge.text must be signed by the user's wallet\n```\n\n### useAuthenticate\n\n_[Lens Reference](https://docs.lens.xyz/docs/login#authenticate)_\n\nAuthenticate the signed challenge\n\n```typescript\nconst [authenticate, { data: authenticateData }] = useAuthenticate(address, signedChallenge);\n\n// Call this method to start the authentication request\nauthenticate();\n\n// After the request is complete\n// authenticateData.authenticate.accessToken has access token\n// authenticateData.authenticate.refreshToken has refresh token\n```\n\n### useRefresh\n\n_[Lens Reference](https://docs.lens.xyz/docs/refresh-jwt)_\n\nRefresh the JWT\n\n```typescript\nconst [refresh, { data: refreshData }] = useRefresh(refreshToken);\n\n// Call this method to start the refresh request\nrefresh();\n\n// After the request is complete\n// refreshData.refresh.accessToken has access token\n// refreshData.refresh.refreshToken has refresh token\n```\n\n## Query\n\nHooks to query the Lens API. Note, some of these require authentication, check the Lens Reference.\n\n### useProfile\n\n_[Lens Reference](https://docs.lens.xyz/docs/get-profile#get-by-handle)_\n\nGet a profile by handle\n\n```typescript\nconst { data } = useProfile(handle);\n```\n\n### useProfiles\n\n_[Lens Reference](https://docs.lens.xyz/docs/get-profiles#get-by-owned-by)_\n\nGet all profiles owned by an address\n\n```typescript\nconst { data } = useProfiles(address);\n```\n\n### useDefaultProfile\n\n_[Lens Reference](https://docs.lens.xyz/docs/get-default-profile)_\n\nGet default profile by address\n\n```typescript\nconst defaultProfile = useDefaultProfile(address);\n```\n\n### useProfilePicture\n\nThe response body from `useProfile` and `useDefaultProfile` is slightly different, so this method helps to pull out the profile picture from one of those.\n\n```typescript\nconst defaultProfile = useDefaultProfile(address);\nconst pfpURL = useProfilePicture(defaultProfile);\n```\n\n### useProfileHasDispatcher\n\nA simple utility which returns `true` if the profile has the dispatcher enabled.\n\n```typescript\nconst dispatch = useProfileHasDispatcher(profileId);\n```\n\n### usePublication\n\n_[Lens Reference](https://docs.lens.xyz/docs/get-publication)_\n\nRetrieve details for a specific publication\n\n```typescript\nconst { data } = usePublication(publicationId);\n\n// Pass in profileId to get the mirrored status in your publication results\nconst { data } = usePublication(publicationId, profileId);\n```\n\n### usePublications\n\n_[Lens Reference](https://docs.lens.xyz/docs/get-publications)_\n\nRetrieve publications based on various parameters\n\n```typescript\n// Get posts from a specific profile\nconst { data } = usePublications(profileId);\n\n// Get posts and comments from a specific profile\nconst { data } = usePublications(profileId, [PublicationType.POST, PublicationType.COMMENT]);\n\n// Get posts from a specific profile and source\nconst { data } = usePublications(profileId, [PublicationType.POST], [\"memester\"]);\n```\n\n### usePublicationComments\n\n_[Lens Reference](https://docs.lens.xyz/docs/get-publications)_\n\nRetrieve publications based on various parameters\n\n```typescript\n// Get comments for a specific publication\nconst { data } = usePublicationComments(publicationId);\n```\n\n### useSearch\n\n_[Lens Reference](https://docs.lens.xyz/docs/search-profiles-and-publications#search-across-profiles)_\n\nSearch profiles\n\n```typescript\nconst { data } = useSearch(\"stani\");\n```\n\n## Write\n\nHooks to write to Lens using the [dispatcher](https://docs.lens.xyz/docs/dispatcher) if enabled or the [broadcaster](https://docs.lens.xyz/docs/broadcast-transaction) if not. Note, your Apollo GraphQL client must be [authenticated](https://docs.lens.xyz/docs/authentication-quickstart)!\n\nAll write hooks take an optional final parameter which allows you to specify callback functions. An example is given for `useCollect` but the same applies to all hooks in this section.\n\n### useCollect\n\nCollect a publication using the API\n\n```typescript\nconst { collect, loading, error } = useCollect(publicationId);\n\n// Call this method to start the collect request\ncollect();\n\n// You can also pass in callback functions\nconst { collect, loading, error } = useCollect(publicationId, {\n  onBroadcasted(receipt) {\n    // ...\n  },\n  onCompleted(receipt) {\n    // receipt will be undefined if the request errored for some reason\n  },\n});\n```\n\n### useComment\n\nComment on a publication. Requires a URL with the comment metadata already uploaded\n\n```typescript\nconst { collect, loading, error } = useComment(profileId, publicationId, commentURL);\n\n// Call this method to start the comment request\ncomment();\n```\n\n### useFollow\n\nFollow a profile\n\n```typescript\nconst { follow, loading, error } = useFollow(profileIdToFollow);\n\n// Call this method to start the follow request\nfollow();\n```\n\n### useUnfollow\n\nUnfollow a profile\n\n```typescript\nconst { unfollow, loading, error } = useUnfollow(profileIdToUnfollow);\n\n// Call this method to start the unfollow request\nunfollow();\n```\n\n### useMirror\n\nMirror a publication\n\n```typescript\nconst { mirror, loading, error } = useMirror(profileId, publicationId);\n\n// Call this method to start the mirror request\nmirror();\n```\n\n### usePost\n\nPost. Requires a URL with the post metadata already uploaded\n\n```typescript\nconst { post, loading, error } = usePost(profileId, postURL);\n\n// Call this method to start the post request\npost();\n```\n\n## Contract\n\n### useContractCollect\n\n_[Lens Reference](https://docs.lens.xyz/docs/functions#collect)_\n\nCollect a publication using the Lens Hub Contract\n\n```typescript\nconst { write, data, prepareError, writeError, status } = useContractCollect(profileId, publicationId);\n\n// Call this method to invoke the users connected wallet\nwrite();\n```\n\n### useContractComment\n\n_[Lens Reference](https://docs.lens.xyz/docs/functions#comment)_\n\nComment on a publication using the Lens Hub Contract\n\n```typescript\nconst { write, data, prepareError, writeError, status } = useContractCollect(\n  profileId,\n  contentURI,\n  profileIdPointed,\n  pubIdPointed,\n  collectModule,\n  collectModuleInitData,\n  referenceModule,\n  referenceModuleInitData,\n  referenceModuleData,\n);\n\n// Call this method to invoke the users connected wallet\nwrite();\n```\n\n### useContractFollow\n\n_[Lens Reference](https://docs.lens.xyz/docs/functions#follow)_\n\nFollow profiles using the Lens Hub Contract\n\n```typescript\nconst { write, data, prepareError, writeError, status } = useContractFollow(profileIds);\n\n// Call this method to invoke the users connected wallet\nwrite();\n```\n\n### useContractUnfollow\n\n_[Lens Reference](https://docs.lens.xyz/docs/follow)_\n\nUnfollow a profile by burning the specific Follow NFT. You must pass in the relevant follow NFT address and tokenId\n\n```typescript\nconst { write, data, prepareError, writeError, status } = useContractUnfollow(followNFTAddress, tokenId);\n\n// Call this method to invoke the users connected wallet\nwrite();\n```\n\n### useContractMirror\n\n_[Lens Reference](https://docs.lens.xyz/docs/functions#mirror)_\n\nMirror a publication using the Lens Hub Contract\n\n```typescript\nconst { write, data, prepareError, writeError, status } = useContractMirror(\n  profileId,\n  profileIdPointed,\n  pubIdPointed,\n  referenceModuleData,\n  referenceModule,\n  referenceModuleInitData,\n);\n\n// Call this method to invoke the users connected wallet\nwrite();\n```\n\n### useContractPost\n\n_[Lens Reference](https://docs.lens.xyz/docs/functions#post)_\n\nPost using the Lens Hub Contract\n\n```typescript\nconst { write, data, prepareError, writeError, status } = useContractPost(\n  profileId?,\n  contentURI,\n  collectModule,\n  collectModuleInitData,\n  referenceModule,\n  referenceModuleInitData,\n);\n\n// Call this method to invoke the users connected wallet\nwrite();\n```\n\n### useContractProfile\n\n_[Lens Reference](https://docs.lens.xyz/docs/view-functions#getprofile)_\n\nRead profile from the Lens Hub Contract\n\n```typescript\nconst { data } = useContractProfile(profileId);\n```\n\n---\n\n_Made with 🫡 by [memester.xyz](https://memester.xyz)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemester-xyz%2Flens-use","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmemester-xyz%2Flens-use","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmemester-xyz%2Flens-use/lists"}