2.2.0 • Published 4 days ago

@lens-protocol/react-native v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

Lens React Native SDK

The official Lens Protocol React bindings for React Native.


This package enables you to build mobile applications on top of the Lens Protocol using React Native.

Documentation

Quick start

Install the Lens React Native SDK package using your package manager of choice:

Package ManagerCommand
npmnpm install @lens-protocol/react-native@latest
yarnyarn add @lens-protocol/react-native@latest
pnpmpnpm add @lens-protocol/react-native@latest

First we need to create so-called bindings. Bindings are just an object implementing the IBindings interface. This is used by the Lens SDK to access the Signer and the Provider.

In this example we will limit ourselves to the bare minimum and we will use the ethers.js library to create the bindings.

// wallet.ts
import { IBindings } from '@lens-protocol/react-native';
import { providers, Wallet } from 'ethers';

const provider = new providers.InfuraProvider('maticmum');
const wallet = new Wallet('<your-private-key>', provider);

export const bindings: IBindings = {
  getProvider: async () => provider,
  getSigner: async () => wallet,
};

Create the LensConfig. In this example we will use react-native-mmkk as underlying storage. You can use any storage you want as long as it implements the IStorageProvider interface.

First install the react-native-mmkv package:

Package ManagerCommand
npmnpm install react-native-mmkv
yarnyarn add react-native-mmkv
pnpmpnpm add react-native-mmkv

Create the LensConfig object:

import { LensConfig, development } from '@lens-protocol/react-web';
import { storage } from '@lens-protocol/react-web/storage/mmkv';
import { bindings } from './wallet.ts';

const lensConfig: LensConfig = {
  bindings,
  environment: development,
  storage: storage(),
};

Wrap your app with the <LensProvider> and pass the LensConfig as a prop.

import { LensProvider } from '@lens-protocol/react-web';

function App() {
  return (
    <LensProvider config={lensConfig}>
      <YourApp />
    </LensProvider>
  );
}