Follow and Unfollow
This guide explains how to follow and unfollow an Account on Lens.
Lens Account can follow other Lens accounts on the Global Graph or on Custom Graphs.
Follow operations are regulated by Follow Rules set on the target Account and by the Graph Rule of the Graph where the follow relationship is established. More information on this will be provided in due course.
Follow an Account
To follow an account, you need to:
Check Follow permissions
Submit a Follow request
All steps in this section assumes are authenticated as Account Owner or Account Manager.
First, inspect the account's operations.canFollow field to determine if you can follow the account.
- GraphQL
- TypeScript
Account
fragment Account on Account { # ...
operations { # defaults to the Global Graph canFollow isFollowedByMe
# or use aliases for a specific Graph # canFollowOnMyGraph: canFollow(request: { graph: "0x123…" }) # isFollowedByMeOnMyGraph: isFollowedByMe(request: { graph: "0x123…" })
# ... }}
The value of which can be:
YES - Your Account meets the follow criteria the target Account Owner has set.
- NO - You cannot follow the target Account. This could be for 2 reasons:
Your Account already follows the target Account, in this case the operation.isFollowedByMe field will be true.
Your Account does not meet the follow criteria the target Account Owner has set.
UNKNWOWN - Indicates the Account's follow permissions are not known. This could be due to the use of a Custom Follow Rule (more on this later).
Then, if your follow request is allowed, you can proceed with submitting the request.
You MUST be authenticated as Account Owner or Account Manager to make this request.
- TypeScript
- GraphQL
- React
Then, use the follow action with the target Account address.
The Lens SDK example here leverages a functional approach to chaining operations using the Result<T, E> object. See the Error Handling guide for more information.
- TypeScript
- GraphQL
- React
Finally, handle the result using the adapter for the library of your choice:
See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.
Unfollow an Account
To unfollow an account, you need to:
Check Unfollow permissions
Submit an Unfollow request
All steps in this section assumes are authenticated as Account Owner or Account Manager.
First, inspect the account's operations.canUnfollow field to determine if you can unfollow the account.
- GraphQL
- TypeScript
- React
Account
fragment Account on Account { # ...
operations { # defaults to the Global Graph canUnfollow isFollowedByMe
# or use aliases for a specific Graph # canUnfollowOnMyGraph: canUnfollow(request: { graph: "0x123…" }) # isFollowedByMeOnMyGraph: isFollowedByMe(request: { graph: "0x123…" }) }}
If true, you can unfollow the account. If false, you might not be following them, in which case the operation.isFollowedByMe field will also be false.
Then, if your unfollow request is allowed, you can proceed with submitting the request.
You MUST be authenticated as Account Owner or Account Manager to make this request.
- TypeScript
- GraphQL
- React
Then, use the unfollow action with the target Account address.
The Lens SDK example here leverages a functional approach to chaining operations using the Result<T, E> object. See the Error Handling guide for more information.
- TypeScript
- GraphQL
- React
Finally, handle the result using the adapter for the library of your choice:
See the Transaction Lifecycle guide for more information on how to determine the status of the transaction.
That's it—you now know how to follow and unfollow an Account on Lens, allowing to manage social connections.