Search Profiles
📘
Full Code Repo - https://github.com/aave/lens-api-examples
Search is a fundamental feature of every social media applications.
This query allows you to search across hashtags on profile handles and publications . The API returns either a Post
, Comment
, or User
depending on the type of object that was found.
Function Parameters
Parameter | Type | Example |
---|---|---|
query | string | `web3 |
type | string | "PROFILE" or "PUBLICATION" |
limit | number | 10 |
API operation
lensjs
.search({
query: 'josh',
type: PROFILE,
limit: 10,
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
API response
{
"search": {
"__typename": "ProfileSearchResult",
"items": [
{
"profileId": "0x032f1a",
"name": "josh stevens",
"bio": "hey this is my profile",
"attributes": [
{
"displayType": null,
"traitType": null,
"key": "custom_field",
"value": "yes this is custom"
}
],
"isFollowedByMe": false,
"isFollowing": false,
"followNftAddress": null,
"metadata": "ipfs://QmSfyMcnh1wnJHrAWCBjZHapTS859oNSsuDFiAPPdAHgHP",
"isDefault": false,
"handle": "joshworld",
"picture": null,
"coverPicture": null,
"ownedBy": "0xEEA0C1f5ab0159dba749Dc0BAee462E5e293daaF",
"dispatcher": {
"address": "0xEEA0C1f5ab0159dba749Dc0BAee462E5e293daaF"
},
"stats": {
"totalFollowers": 0,
"totalFollowing": 2,
"totalPosts": 4,
"totalComments": 0,
"totalMirrors": 1,
"totalPublications": 5,
"totalCollects": 0
},
"followModule": {
"type": "FeeFollowModule",
"amount": {
"asset": {
"name": "WETH",
"symbol": "WETH",
"decimals": 18,
"address": "0x3C68CE8504087f89c640D02d133646d98e64ddd9"
},
"value": "0.01"
},
"recipient": "0xEEA0C1f5ab0159dba749Dc0BAee462E5e293daaF"
}
}
],
"pageInfo": {
"prev": "{\"offset\":0}",
"totalCount": 1,
"next": "{\"offset\":10}"
}
}
}
Full Code Example
import lensjs from 'lensjs';
import { useEffect } from 'react';
export default function Example(params) {
useEffect(() => {
lensjs
.search(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
}, []);
}