To comment on a post, you must have the original post’s ID and the author’s shared user ID.React Hook Example for Creating Comments:
import { usePost } from '@sageprotocol/sdk/react';import { useWallet } from '@suiet/wallet-kit';function CreateComment({ parentPostId, authorSharedUserId, ownedUserId }) { const { commentOnPost } = usePost(); const { account, signAndExecuteTransaction } = useWallet(); async function handleCreateComment() { const result = await commentOnPost({ amounts: [0, 0], // Required protocol fees appId: 'your-app-id', // Required application ID network: 'testnet', // 'testnet' or 'mainnet' authorSharedUserId, // Original post author's shared user ID parentPostId, // ID of the parent post title: 'Great insights!', // Comment title in markdown description: 'Adding my perspective', // Comment summary in markdown data: 'I completely agree with your points, especially regarding scalability...', // Main markdown
Direct JavaScript Example for Creating Comments
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 createComment(parentPostId, authorSharedUserId, ownedUserId, walletAddress) { const result = await sageClient.commentOnPost({ amounts: [0, 0], // Required protocol fees authorSharedUserId, // Original post author's shared user ID parentPostId, // ID of the parent post title: 'Great insights!', // Comment title in markdown description: 'Adding my perspective', // Comment summary in markdown data: 'I completely agree with your points, especially regarding scalability...', // Main markdown content ownedUserId, // Commenter's owned user ID self: walletAddress // Commenter's wallet address }); if (result.ok) { await signAndExecuteTransaction({ transaction: result.transaction }); console.log("Comment created successfully!"); } else { console.error("Error creating comment:", result.err); }}createComment('parent-post-id', 'author-shared-user-id', 'your-owned-user-id', walletAddress);