Fetch Accounts
This guide will help you with fetching Account data from the Lens API.
Lens Account data is comprised of:
Account Identity
Account Metadata
ML Score
Operational flags
To illustrate how to fetch accounts, we will use the following fragment, which includes some of the most common fields of an Account:
Account
fragment Account on Account { address username { value } metadata { name picture }}
In the end of this guide, we will expand on some of the fields that are not fully covered in the example above.
Get an Account
- TypeScript
- GraphQL
- React
Use the fetchAccount action to fetch an Account by its address, username, txHash or legacy Lens v2 ID.
Bulk Accounts List
- GraphQL
- React
- TypeScript
Use the accountsBulk query to fetch a finite number of accounts by their addresses, usernames, or legacy Lens v2 IDs.
Search Accounts
- TypeScript
- GraphQL
- React
Use the paginated fetchAccounts action to search for accounts by their usernames.
Continue with the Pagination guide for more information on how to handle paginated results.
Account Fields
In this section we will expand on some of the Account fields that are not covered in the examples above.
Account Identity
An Account can have one or more usernames across different namespaces, but only one username per namespace.
By default, the username field returns the username in the lens/ namespace, if available. It also accepts an optional argument to specify a different namespace.
Account Metadata
Although briefly mentioned in the examples, the metadata field is a rich object that can include a variety of information about the account.
It contains the Account Metadata object that was linked to the Account at the time of creation or update. This object can include the following fields:
See the Create an Account guide for more information on how this object is created.
Account Score
The Lens team has implemented a series of measures to uphold the integrity of the Lens ecosystem. The Account Score is a probability-based measure that evaluates an account's signal strength, helping to reduce the impact of spammy behavior on the user experience. This score is calculated using a set of ML algorithms that consider factors like follower graphs, content, and other variables. Higher scores suggest a positive and active presence within the ecosystem.
Fragment
fragment Account on Account { # ...
score}
Logged-In Operations
The Lens schema allows logged-in users to fetch details about available actions and actions already taken, via the operations field.
The LoggedInAccountOperations type specifies the actions the user can perform (e.g., canFollow, canBlock) and the actions already taken (e.g., isFollowedByMe, isBlockedByMe).
Where:
isFollowedByMe: Indicates whether the logged-in account follows the account.
isFollowingMe: Indicates whether the account follows the logged-in account.
canFollow: Indicates whether the logged-in account can follow the account.
canUnfollow: Indicates whether the logged-in account can unfollow the account.
isMutedByMe: Indicates whether the account is muted by the logged-in account.
isBlockedByMe: Indicates whether the account is blocked by the logged-in account.
hasBlockedMe: Indicates whether the account has blocked the logged-in account.
canBlock: Indicates whether the logged-in account can block the account.
canUnblock: Indicates whether the logged-in account can unblock the account.
hasReported: Indicates whether the logged-in account has reported the account.
Fields returning an OperationValidationOutcome give information on the feasibility of the operation. More details in the Querying Data guide.
The isFollowedByMe, isFollowingMe, canFollow, and canUnfollow fields accept an optional argument specifying the Graph address to check the follow status.
- GraphQL
- TypeScript
Alias the corresponding fields as needed:
LoggedInAccountOperations
fragment LoggedInAccountOperations on LoggedInAccountOperations { isFollowedByMeOnMyGraph: isFollowedByMe(request: { graph: "0x1234…" })
isFollowingMeOnMyGraph: isFollowingMe(request: { graph: "0x1234…" })
canFollowOnMyGraph: canFollow(request: { graph: "0x1234…" }) { ...OperationValidationOutcome }
canUnfollowOnMyGraph: canUnfollow(request: { graph: "0x1234…" }) { ...OperationValidationOutcome }}
If an argument is not provided, the query follows a fallback approach:
It first checks for a Graph address specified within the query scope.
If no Graph address is found, it defaults to using the global Lens Graph.