Channel owners can update channel information including descriptions, avatars, banners, and the casing of channel names. Updates require explicitly providing all fields to avoid unintended overwrites; unchanged fields should retain existing values.React Hook Example for Updating Channels:
Copy
import { useChannel } from '@sageprotocol/sdk/react';import { useWallet } from '@suiet/wallet-kit';function UpdateChannel({ channel }) { const { update } = useChannel(); const { account, signAndExecuteTransaction } = useWallet(); async function handleUpdate() { const result = await update({ amounts: [0, 0], // Required protocol fees avatar: channel.avatar, // Existing or updated blob ID banner: channel.banner, // Existing or updated blob ID channelId: channel.id, // Channel ID channelName: channel.name, // Casing updates only (e.g., 'crypto-art' → 'CRYPTO-ART') description: '**Updated community guidelines and information**', // Markdown-supported description self: account.address // Channel owner's wallet address }); if (result.ok) { await signAndExecuteTransaction({ transaction: result.transaction }); console.log("Channel updated successfully!"); } else { console.error("Error updating channel:", result.err); } } return <button onClick={handleUpdate}>Update Channel</button>;}export default UpdateChannel;
Direct JavaScript Example for Updating Channels
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 updateChannel(channel, walletAddress) { const result = await sageClient.updateChannel({ amounts: [0, 0], // Required protocol fees avatar: channel.avatar, // Existing or updated blob ID banner: channel.banner, // Existing or updated blob ID channelId: channel.id, // Channel ID channelName: channel.name, // Casing updates only description: '**Updated community guidelines and information**', // Markdown-supported description self: walletAddress // Channel owner's wallet address }); if (result.ok) { await signAndExecuteTransaction({ transaction: result.transaction }); console.log("Channel updated successfully!"); } else { console.error("Error updating channel:", result.err); }}updateChannel({ id: 'your-channel-id', avatar: 12345, banner: 67890, name: 'crypto-art'}, walletAddress);