Only users who follow channels can create posts within them. Channel posts support rich markdown content, including formatting, images, and embedded links.React Hook Example for Posting Content in Channels:
import { usePost } from '@sageprotocol/sdk/react';import { useWallet } from '@suiet/wallet-kit';function PostToChannel({ channelId, ownedUserId }) { const { postToChannel } = usePost(); const { account, signAndExecuteTransaction } = useWallet(); async function handlePost() { const result = await postToChannel({ amounts: [0, 0], // Required, typically [0, 0] appId: 'your-app-id', // Explicitly required application ID network: 'testnet', // Required network ('testnet' or 'mainnet') channelId, // Channel ID where post is created data: 'Sui offers significantly higher transaction throughput...', // Main markdown content description: 'Performance and scalability comparison', // Markdown summary title: 'Understanding Sui vs Ethereum', // Post title in markdown 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 channel successfully!"); } else { console.error("Error posting to channel:", result.err); } } return <button onClick={handlePost}>Post Content</button>;}export default PostToChannel;
Direct Javascript Example for Posting Content in Channels
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 postToChannel(channelId, ownedUserId, walletAddress) { const result = await sageClient.postToChannel({ amounts: [0, 0], // Required, typically [0, 0] channelId, // Channel ID where post is created data: 'Sui offers significantly higher transaction throughput...', // Main markdown content description: 'Performance and scalability comparison', // Markdown summary title: 'Understanding Sui vs Ethereum', // Post title in markdown ownedUserId, // Poster’s owned user ID self: walletAddress // Poster’s wallet address }); if (result.ok) { await signAndExecuteTransaction({ transaction: result.transaction }); console.log("Posted to channel successfully!"); } else { console.error("Error posting to channel:", result.err); }}postToChannel('your-channel-id', 'your-owned-user-id', walletAddress);