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
Name | Description |
---|---|
LensChainId | The chain ID for the Lens Chain mainnet |
LensChainTestnetId | The chain ID for the Lens Chain testnet |
NativeToken | The native token address in Lens Chain |
ZeroAddress | A zero (or empty) address in EVM-compatible blockchains |
Functions
arweaveUrlToGatewayUrl string
Convert an Arweave URL to a gateway URL
Props
Prop | Description | Type |
---|---|---|
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
Prop | Description | Type |
---|---|---|
count | The follower count to format | number |
getAudioExtension string
Get the file extension for a given MediaAudioType
Props
Prop | Description | Type |
---|---|---|
mediaAudioType | The MediaAudioType to get the extension for | MediaAudioType |
getCidFromIpfsUrl string
Extract the CID from an IPFS URL
Props
Prop | Description | Type |
---|---|---|
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
Prop | Description | Type |
---|---|---|
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
Prop | Description | Type |
---|---|---|
username |
| string |
namespace |
| EvmAddress |
getVideoExtension string
Get the file extension for a given MediaVideoType
Props
Prop | Description | Type |
---|---|---|
mediaVideoType | The MediaVideoType to get the extension for | MediaVideoType |
ipfsUrlToGatewayUrl string
Convert an IPFS URL to a gateway URL
Props
Prop | Description | Type |
---|---|---|
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
Prop | Description | Type |
---|---|---|
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
Prop | Description | Type |
---|---|---|
uri | The URI to parse | string |
truncateAddress string
Truncate a string to a maximum length, adding an ellipsis in the middle
Props
Prop | Description | Type |
---|---|---|
address | The string to truncate | string |
maxLength | The maximum length of the truncated string, excluding the ellipsis and 0x prefix | number |