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.
Follow an Account
To follow an Account, implement the following steps.
You MUST be authenticated as Account Owner or Account Manager to follow an Account.
First, inspect the account.operations field to determine if you can follow an Account.
- TypeScript
- GraphQL
The account.operations.canFollow can assume one of the following values:
Check Rules
switch (account.operations.canFollow.__typename) { case "AccountFollowOperationValidationPassed": // Follow is allowed break;
case "AccountFollowOperationValidationFailed": // Following is not possible console.log(account.operations.canFollow.reason); break;
case "AccountFollowOperationValidationUnknown": // Validation outcome is unknown break;}
Where:
-
AccountFollowOperationValidationPassed: The logged-in Account can follow the target Account.
-
AccountFollowOperationValidationFailed: Following is not allowed. The reason field explains why. This could be for two reasons:
The logged-in Account already follows the target Account. In this case, the account.operation.isFollowedByMe field will be true.
The logged-in Account does not meet the follow criteria for the target Account. In this case, unsatisfiedRules lists the unmet requirements.
-
AccountFollowOperationValidationUnknown: The target Account or the Graph (for custom Graphs) has one or more unknown rules requiring ad-hoc verification. The extraChecksRequired field provides the addresses and configurations of these rules.
Treat the AccountFollowOperationValidationUnknown as failed unless you intend to support the specific rules. See Follow Rules for more information.
Then, if your follow request is allowed, you can proceed with submitting the 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, implement the following steps.
You MUST be authenticated as Account Owner or Account Manager to follow an Account.
First, inspect the account.operations field to determine if you can unfollow an Account.
- TypeScript
- GraphQL
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.
Where:
-
AccountFollowOperationValidationPassed: The logged-in Account can unfollow the target Account.
-
AccountFollowOperationValidationFailed: Following is not allowed. The reason field explains why. This could be for two reasons:
The logged-in Account does not follow the target Account. In this case, the account.operation.isFollowedByMe field will be false.
The logged-in Account does not meet the follow criteria for the target Account. In this case, unsatisfiedRules lists the unmet requirements.
-
AccountFollowOperationValidationUnknown: The custom Graph has one or more unknown rules requiring ad-hoc verification. The extraChecksRequired field provides the addresses and configurations of these rules.
Treat the AccountFollowOperationValidationUnknown as failed unless you intend to support the specific rules. See Follow Rules for more information.
Then, if your unfollow request is allowed, you can proceed with submitting the 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 your social graph.