Posts are central to Sage Protocol’s content interactions, enabling rich markdown formatting and transparent blockchain-native interactions across channels and user profiles.
Users can directly post onto profiles for personal interactions, endorsements, or recommendations.React Hook Example for Posting to User Profiles:
Copy
import { usePost } from '@sageprotocol/sdk/react';import { useWallet } from '@suiet/wallet-kit';function PostToUser({ targetSharedUserId, ownedUserId }) { const { postToUser } = usePost(); const { account, signAndExecuteTransaction } = useWallet(); async function handlePostToUser() { const result = await postToUser({ amounts: [0, 0], // Required protocol fees appId: 'your-app-id', // Required application ID network: 'testnet', // 'testnet' or 'mainnet' sharedUserId: targetSharedUserId, // Target user's shared user ID title: 'Professional Endorsement', // Post title in markdown description: 'Recognizing outstanding contributions', // Markdown summary data: 'Thanks for your amazing support and mentorship!', // Main markdown content ownedUserId, // Poster's owned user ID self: account.address // Poster's wallet address }); if (result.ok) { await signAndExecuteTransaction({ transaction: result.transaction }); console.log("Posted to user profile successfully!"); } else { console.error("Error posting to user profile:", result.err); } } return <button onClick={handlePostToUser}>Post to User</button>;}export default PostToUser;
Direct JavaScript Example for Posting to User Profiles
Copy
import { SageClient } from '@sageprotocol/sdk';const sageClient = new SageClient({ appId: 'your-app-id', // Required application ID channelRegistryId: 'your-registry-id', // Required channel registry ID network: 'testnet' // 'testnet' or 'mainnet'});await sageClient.initialize();async function postToUser(targetSharedUserId, ownedUserId, walletAddress) { const result = await sageClient.postToUser({ amounts: [0, 0], // Required protocol fees sharedUserId: targetSharedUserId, // Target user's shared user ID title: 'Professional Endorsement', // Post title in markdown description: 'Recognizing outstanding contributions', // Markdown summary data: 'Thanks for your amazing support and mentorship!', // Main markdown content ownedUserId, // Poster's owned user ID self: walletAddress // Poster's wallet address }); if (result.ok) { await signAndExecuteTransaction({ transaction: result.transaction }); console.log("Posted to user profile successfully!"); } else { console.error("Error posting to user profile:", result.err); }}postToUser('target-shared-user-id', 'your-owned-user-id', walletAddress);