Lens Blocks are currently in pre-alpha and not ready for use!

Utilities Library

Utility functions for interacting with Lens Social Protocol, including formatting and data manipulation.

Installation

Usage

The utilities provided in this module can be imported and used in your project as follows:

Constants

NameDescription
LensChainIdThe chain ID for the Lens Chain mainnet
LensChainTestnetIdThe chain ID for the Lens Chain testnet
NativeTokenThe native token address in Lens Chain
ZeroAddressA zero (or empty) address in EVM-compatible blockchains

Functions

arweaveUrlToGatewayUrl string

Convert an Arweave URL to a gateway URL

Props

PropDescriptionType
arUrl

The Arweave URL to convert

string
gatewayDomain

The gateway domain to use (default: https://arweave.net/)

string

formatFollowerCount string

Format a follower count as a string, using "k" for thousands and "m" for millions

Props

PropDescriptionType
count

The follower count to format

number

getAudioExtension string

Get the file extension for a given MediaAudioType

Props

PropDescriptionType
mediaAudioType

The MediaAudioType to get the extension for

MediaAudioType

getCidFromIpfsUrl string

Extract the CID from an IPFS URL

Props

PropDescriptionType
ipfsUrl

The IPFS URL to extract the CID from

string

getDisplayName string

Get the display name for an account, prioritizing the metadata name, then the username, and finally truncating the address.

Props

PropDescriptionType
account

The account to get the display name for

Account

getUsernamePath string

Get the path for a Lens username, optionally including the namespace if it's not the default "lens" namespace.

Props

PropDescriptionType
username
  • The full username, including the namespace (e.g., "@lens/username")
string
namespace
  • The namespace address of the username. If not provided, the default namespace will be assumed.
EvmAddress

getVideoExtension string

Get the file extension for a given MediaVideoType

Props

PropDescriptionType
mediaVideoType

The MediaVideoType to get the extension for

MediaVideoType

ipfsUrlToGatewayUrl string

Convert an IPFS URL to a gateway URL

Props

PropDescriptionType
ipfsUrl

The IPFS URL to convert

string
gatewayDomain

The gateway domain to use (default: https://ipfs.io/ipfs/)

string

lensUrlToGatewayUrl string

Convert a Lens URL to a gateway URL

Props

PropDescriptionType
lensUrl

The Lens URL to convert

string
gatewayDomain

The gateway domain to use (default: https://api.grove.storage/)

string

parseUri string | undefined

Parse a URI and convert it to a gateway URL if it is an IPFS, Arweave, or Lens URL

Props

PropDescriptionType
uri

The URI to parse

string

truncateAddress string

Truncate a string to a maximum length, adding an ellipsis in the middle

Props

PropDescriptionType
address

The string to truncate

string
maxLength

The maximum length of the truncated string, excluding the ellipsis and 0x prefix

number