The Gated module is a secondary entry point of the @lens-protocol/client package.
It provides an alternative Gated.LensClient class that supports all the
functionalities of the Core.LensClient plus the Gated module.
The reason for this separation is that token-gated feature requires extra 3rd party dependencies
that could potentially impact the bundle size of your application. This way the
developer have the choice to opt-in for token-gated support only when needed.
The usage is the same as the Core.LensClient class, but with the addition of
token gated configuration Gated.LensClientConfig: authentication, signer, and encryption.
constcondition = collectCondition({ publicationId:awaitclient.publication.predictNextOnChainPublicationId({ from:profile.id, }), thisPublication:true, // flag to indicate that the current publication is the one to collect });
// fetch a publication, works with publications returned by any LensClient method constpost = awaitclient.publication.fetch({ forId:'...' });
// check if the publication metadata is encrypted if (isEncryptedPublicationMetadata(post.metadata)) {
// decrypt the metadata constresult = awaitclient.gated.decryptPublicationMetadataFragment(post.metadata);
// handle decryption errors if (result.isFailure()) { console.error(result.error); return; // bail out }
// use the decrypted metadata console.log(result.value); }
⚠️ In case you find yourself using this feature with publication metadata fragment not originated from the LensClient
it's your responsibility to make sure the PublicationMetadata fragment is valid by making sure it:
has __typename defined at every level of the fragment
has the encryptedWith including ALL fields and sub-fields of the corresponding GQL node.
The Gated module is a secondary entry point of the
@lens-protocol/clientpackage. It provides an alternative Gated.LensClient class that supports all the functionalities of the Core.LensClient plus the Gated module.The reason for this separation is that token-gated feature requires extra 3rd party dependencies that could potentially impact the bundle size of your application. This way the developer have the choice to opt-in for token-gated support only when needed.
The usage is the same as the Core.LensClient class, but with the addition of token gated configuration Gated.LensClientConfig:
authentication,signer, andencryption.Quick start
Install the required peer dependencies.
Typical NodeJS setup:
Browser setup with
ethersv6 and an EIP-1193 wallet (e.g. MetaMask):Encryption
You can encrypt publication metadata using the Gated.encryptPublicationMetadata method.
What's happening?
@lens-protocol/metadatahelpers,contentURIto create a Lens publication.Simple criteria
Supported criteria available as helpers in the
@lens-protocol/metadatapackage:collectCondition- the collection of a given publication is requiredeoaOwnershipCondition- the ownership of a given EOA is requirederc20OwnershipCondition- the ownership of a given ERC20 amount is requirederc721OwnershipCondition- the ownership of a given ERC721 token is requirederc1155OwnershipCondition- the ownership of a given ERC1155 token is requiredprofileOwnershipCondition- the ownership of a given profile is requiredfollowCondition- following a given profile is requiredRefer to the
@lens-protocol/metadatareference for more details.Collect this publication
It's possible to define an access condition where one of the criteria is to collect the current publication.
Because at the time of encryption the publication is not yet created, the Core.Publication.predictNextOnChainPublicationId can be used to predict the publication ID.
Compound criteria
Multiple criteria can be combined using the
orConditionandandConditionhelpers.Supported compound criteria:
andCondition- up to 5 criteria can be combined using the AND operator (exceptorConditionandandCondition)orCondition- up to 5 criteria can be combined using the OR operator (exceptorConditionandandCondition)Decryption
You can decrypt publication metadata using the Gated.decryptPublicationMetadataFragment method.
The method works seamlessly with publications returned by any
LensClientmethod.⚠️ In case you find yourself using this feature with publication metadata fragment not originated from the
LensClientit's your responsibility to make sure thePublicationMetadatafragment is valid by making sure it:__typenamedefined at every level of the fragmentencryptedWithincluding ALL fields and sub-fields of the corresponding GQL node.