Skip to Content

Social Graph

🚧

Coming Soon — The ChainSocial SDK is not yet published. This documentation describes the planned API. Use the REST API for current integrations.

Build social relationships with follow/unfollow and user blocking.

Following Users

Follow

await client.follow.follow('0x1234...')

Unfollow

await client.follow.unfollow('0x1234...')

Check Follow Status

const isFollowing = await client.follow.isFollowing( myAddress, // follower theirAddress // followed ) console.log('Following:', isFollowing) // true or false

Batch Follow

Follow multiple users in one transaction (max 50):

const usersToFollow = [ '0x1111...', '0x2222...', '0x3333...' ] const result = await client.follow.followBatch(usersToFollow) console.log(`Followed ${result.count} users`)

Reading Social Graph (API)

Get Followers

const response = await fetch(`https://api.chainsocial.cc/api/users/${address}/followers?limit=50`) const data = await response.json() for (const follower of data.items) { console.log(`@${follower.username} - ${follower.followerCount} followers`) }

Get Following

const response = await fetch(`https://api.chainsocial.cc/api/users/${address}/following?limit=50`) const data = await response.json() for (const following of data.items) { console.log(`Following @${following.username}`) }

API Response Structure

{ "items": [ { "address": "0x...", "username": "bob", "isVerified": false, "followerCount": 150, "followingCount": 42, "lastActiveAt": 1704153600 } ], "page": { "limit": 50, "offset": 0 } }

Follower/Following Counts

Get counts from the profile endpoint:

const response = await fetch(`https://api.chainsocial.cc/api/profiles/${address}`) const data = await response.json() console.log('Followers:', data.followerCount) console.log('Following:', data.followingCount)

Blocking Users

Block a user to prevent them from:

  • Following you
  • Sending you DMs
  • Appearing in your feed

Block

await client.block.block('0x1234...')

Unblock

await client.block.unblock('0x1234...')

Check Block Status

const isBlocked = await client.block.isBlocked( myAddress, // blocker theirAddress // blocked )

Blocking is one-way. If you block someone, they can still see your public content, but they cannot interact with you.

Delegation: On-Behalf-Of

Act on behalf of another user (requires delegation permission):

// Follow as delegate await client.follow.followOnBehalfOf( delegatorAddress, // Who is following targetAddress // Who to follow ) // Unfollow as delegate await client.follow.unfollowOnBehalfOf(delegatorAddress, targetAddress)

Common Patterns

Follow Button Component

function FollowButton({ targetAddress, isFollowing: initialFollowing }) { const client = useChainSocialClient() const [isFollowing, setIsFollowing] = useState(initialFollowing) const [loading, setLoading] = useState(false) const handleClick = async () => { if (!client) return setLoading(true) try { if (isFollowing) { await client.follow.unfollow(targetAddress) setIsFollowing(false) } else { await client.follow.follow(targetAddress) setIsFollowing(true) } } catch (error) { console.error('Follow action failed:', error) } finally { setLoading(false) } } return ( <button onClick={handleClick} disabled={loading}> {loading ? '...' : isFollowing ? 'Unfollow' : 'Follow'} </button> ) }

Suggested Users to Follow

async function getSuggestedUsers(limit = 10) { // Get popular users const response = await fetch( `https://api.chainsocial.cc/api/explore/users/popular?limit=${limit}` ) const data = await response.json() return data.items }

Mutual Followers

Check if two users follow each other:

async function areMutuals(client, addressA, addressB) { const [aFollowsB, bFollowsA] = await Promise.all([ client.follow.isFollowing(addressA, addressB), client.follow.isFollowing(addressB, addressA) ]) return aFollowsB && bFollowsA }

Constraints

  • Cannot follow yourself
  • Cannot follow the zero address
  • Cannot follow blocked users
  • Batch operations limited to 50 users

Next Steps