Skip to main content
Before diving into advanced SDK usage, it’s important to understand a few key concepts and patterns central to Sage Protocol and its SDK. This section covers essential architectural and usage details to ensure a smooth integration process.

Application Isolation and Context (appId)

Sage Protocol isolates content and interactions per application by using a unique identifier (appId). Each application maintains distinct channels and posts, while user identities and social graphs remain global across all Sage-compatible apps. What this means for you:
  • Users have a single, global identity and consistent social relationships everywhere.
  • Each application provides tailored content and distinct community interactions..
Example React Integration using appId:
This structure demonstrates how applications utilize distinct contexts (appId) to maintain content isolation while benefiting from universal user identities.

Invite-Based User Creation (Temporary)

Currently, Sage Protocol requires invite codes and keys for user creation. This temporary mechanism allows applications to control growth and maintain initial engagement quality.
  • Invite Code: Unique code authorizing user creation.
  • Invite Key: Secure key accompanying the invite code.
(Note: Future protocol versions will make invite codes optional.) Example React Hook for Creating Users with Invites:

Transaction Patterns

Sage SDK operations involving blockchain transactions follow a two-step pattern:
  1. Construct Transaction: SDK methods return transaction objects to be signed.
  2. Sign and Execute Transaction: Your React app securely handles wallet interactions for transaction execution.
Example transaction workflow in React:
Replace someAction with the specific method name you’re invoking from sageClient. This accurately represents the direct JavaScript integration pattern documented in your SDK.
This approach ensures secure, transparent blockchain interactions.

Error Handling

The Sage SDK consistently provides structured results indicating success or errors. Every SDK call returns an object with:
  • ok: Boolean indicating success (true) or failure (false).
  • err: Error details if the call fails.
Recommended React Error Handling Pattern:
Always verify transactions by checking the ok property before proceeding.

Event Monitoring and Querying

The Sage SDK provides explicit event-monitoring capabilities. Events (e.g., user creation, posts, channel updates) are emitted on-chain, enabling your application to:
  • React to user actions in real-time.
  • Gather precise analytics and track activity.
Example: Querying new user creation events using React hooks:

React Context and Hooks

For React apps, the Sage SDK provides built-in context (SageProvider) and custom hooks (useUser, useChannel, usePost) to simplify state management and interactions with blockchain primitives. Example: Following a channel using React hooks:
Leveraging these hooks ensures cleaner, more maintainable React code.

Next Steps

With these key concepts clarified, you’re now well-equipped to explore Sage SDK’s core primitives and fully utilize its powerful decentralized social functionalities. Proceed to:
  • Learn detailed management of the core primitives:
  • Advanced Guides: See complete examples for building sophisticated decentralized social apps.
  • API Reference: Explore comprehensive details on SDK methods and capabilities.