Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@lens-protocol/react-web
Advanced tools
The official Lens Protocol React bindings for web applications.
This package enables you to build web applications on top of the Lens Protocol using React.
Install the Lens React Web SDK package using your package manager of choice:
Package Manager | Command |
---|---|
npm | npm install @lens-protocol/react-web@latest |
yarn | yarn add @lens-protocol/react-web@latest |
pnpm | pnpm add @lens-protocol/react-web@latest |
In the following examples we will show you integration with Wagmi and we will explain later how to integrate other libraries via custom bindings.
Install the Lens Wagmi bindings package and its peer dependencies.
Package Manager | Command |
---|---|
npm | npm install viem@2 wagmi@2 @tanstack/react-query@5 @lens-protocol/wagmi@latest |
yarn | yarn add viem@2 viem@2 wagmi@2 @tanstack/react-query@5 @lens-protocol/wagmi@latest |
pnpm | pnpm add viem@2 viem@2 wagmi@2 @tanstack/react-query@5 @lens-protocol/wagmi@latest |
Follow the Wagmi documentation to create the Wagmi configuration.
import { createConfig, http } from 'wagmi';
import { polygon } from 'wagmi/chains';
const wagmiConfig = createConfig({
chains: [polygon],
transports: {
[polygon.id]: http(),
},
});
Next, use this configuration with the bindings
from the @lens-protocol/wagmi
package to generate the LensConfig object.
import { LensConfig, production } from '@lens-protocol/react-web';
import { bindings } from '@lens-protocol/wagmi';
const lensConfig: LensConfig = {
environment: production,
bindings: bindings(wagmiConfig),
};
Now, wrap your app with the <LensProvider>
component and pass the LensConfig
object you created earlier.
import { LensProvider } from '@lens-protocol/react-web';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { WagmiProvider } from 'wagmi';
const queryClient = new QueryClient();
function App() {
return (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<LensProvider config={lensConfig}>
<YourApp />
</LensProvider>
</QueryClientProvider>
</WagmiProvider>
);
}
You can create custom bindings for your own Signer
and Provider
by implementing the {@link IBindings} interface.
An example of how to create custom bindings for a Wallet
from ethers.js
import { InfuraProvider, Wallet } from 'ethers';
import { IBindings } from '@lens-protocol/react-web';
const provider = new providers.InfuraProvider('maticmum');
const wallet = new Wallet('<your-private-key>', provider);
const bindings: IBindings = {
getProvider: () => provider,
getSigner: () => wallet,
};
These are some common issues you may run into while using @lens-protocol/react
. If you encounter something not listed here try searching for GitHub issues.
You might see your Next.js failing with an error like this:
Error: Directory import '[...]/node_modules/@apollo/client/link/context' is not supported resolving ES modules imported from [...]/node_modules/@lens-protocol/api-bindings/dist/index.js
Did you mean to import @apollo/client/link/context/context.cjs?
The root cause is the lack of ESM support from Apollo Client which manifests itself when imported as sub-dependency of @lens-protocol/api-bindings
(which in turn is imported by @lens-protocol/react
). See open Apollo Client issue.
To fix it you need to edit you next.config.js
so to make sure the Lens SDK and its sub-dependencies a transpiled by Next.js build pipeline.
const nextConfig = {
transpilePackages: ['@lens-protocol'],
};
For further details on how to integrate Lens SDK with a Next.js app, there is a working Next.js example in this monorepo: https://github.com/lens-protocol/lens-sdk/tree/main/examples/nextjs
FAQs
Lens Protocol SDK for React web applications
We found that @lens-protocol/react-web demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.