Skip to Content
Quick Start

Quick Start

Get ChainSocial running in your app in under 5 minutes.

Prerequisites

  • Node.js 18+
  • A wallet with some ETH on Base (for gas)
  • Basic familiarity with TypeScript and viem

Installation

pnpm add @chainsocial/client viem

Setup

Create a viem client

First, set up your viem clients. You need a publicClient for reading data and a walletClient for writing.

import { createPublicClient, createWalletClient, http } from 'viem' import { base } from 'viem/chains' import { privateKeyToAccount } from 'viem/accounts' // For reading data const publicClient = createPublicClient({ chain: base, transport: http('https://mainnet.base.org') }) // For writing data (use your preferred wallet connection method) const account = privateKeyToAccount('0x...') // In production, use wallet connection const walletClient = createWalletClient({ account, chain: base, transport: http('https://mainnet.base.org') })

Never hardcode private keys in production. Use a wallet connection library like wagmi, RainbowKit, or ConnectKit.

Create the ChainSocial client

import { createChainSocialClient } from '@chainsocial/client' const client = createChainSocialClient({ worldAddress: '0x7405fCbEc24C00278b7e821Ace222f5CFfa6c6eA', publicClient, walletClient })

Create your first post

// Create a post with inline text (stored on-chain) const result = await client.post.createInlinePost('Hello, ChainSocial!') console.log('Post created!') console.log('Transaction:', result.hash) console.log('Post ID:', result.postId)

Read posts from the API

// Fetch recent posts const response = await fetch('https://api.chainsocial.cc/api/feed?limit=10') const data = await response.json() for (const item of data.items) { console.log(`@${item.author?.username}: ${item.post.content}`) }

Complete Example

Here’s a full working example that creates a post and reads the feed:

import { createPublicClient, createWalletClient, http } from 'viem' import { base } from 'viem/chains' import { privateKeyToAccount } from 'viem/accounts' import { createChainSocialClient } from '@chainsocial/client' // Configuration const WORLD_ADDRESS = '0x7405fCbEc24C00278b7e821Ace222f5CFfa6c6eA' const RPC_URL = 'https://mainnet.base.org' async function main() { // Setup clients const publicClient = createPublicClient({ chain: base, transport: http(RPC_URL) }) // In production, connect wallet via UI instead const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`) const walletClient = createWalletClient({ account, chain: base, transport: http(RPC_URL) }) // Create ChainSocial client const client = createChainSocialClient({ worldAddress: WORLD_ADDRESS, publicClient, walletClient }) // Create a post console.log('Creating post...') const result = await client.post.createInlinePost('Hello from ChainSocial!') console.log('Post created:', result.postId) // Wait a moment for indexer to pick it up await new Promise(resolve => setTimeout(resolve, 3000)) // Read the feed console.log('\nRecent posts:') const response = await fetch('https://api.chainsocial.cc/api/feed?limit=5') const data = await response.json() for (const item of data.items) { const author = item.author?.username || item.post.author.slice(0, 10) const content = item.post.content?.slice(0, 50) || '[no content]' console.log(`- @${author}: ${content}`) } } main().catch(console.error)

Using with React

Here’s how to integrate with a React app using wagmi:

import { useAccount, usePublicClient, useWalletClient } from 'wagmi' import { createChainSocialClient } from '@chainsocial/client' import { useMemo } from 'react' const WORLD_ADDRESS = '0x7405fCbEc24C00278b7e821Ace222f5CFfa6c6eA' function useChainSocialClient() { const publicClient = usePublicClient() const { data: walletClient } = useWalletClient() return useMemo(() => { if (!publicClient) return null return createChainSocialClient({ worldAddress: WORLD_ADDRESS, publicClient, walletClient: walletClient ?? undefined }) }, [publicClient, walletClient]) } function PostButton() { const client = useChainSocialClient() const { isConnected } = useAccount() const handlePost = async () => { if (!client) return const result = await client.post.createInlinePost('Hello from React!') alert(`Posted! ID: ${result.postId}`) } if (!isConnected) return <button disabled>Connect wallet to post</button> return <button onClick={handlePost}>Create Post</button> }

What’s Next?

You’ve created your first post. Here’s where to go from here:

  • Profiles — Create and update user profiles
  • Posts — Learn about replies, quotes, reactions, and media
  • Social Graph — Follow users and build social features
  • API Reference — Use the REST API for read-heavy operations

Need a profile first? Before posting, users need a profile. If you get an error about requiring a profile, see the Profiles guide to create one.