Sage SDK
  • Getting Started
    • Installation
    • Frontend
    • Server
    • Error Handling
  • Channel
    • Create
    • Membership
    • Moderation
  • Post
  • Update
  • Invite
    • Creation
    • Deletion
  • Post
    • Comment
    • Like
  • User
    • Create
    • Membership
    • Post
    • Update
Powered by GitBook
On this page
  • Update a Sage channel
  • Error Codes
  • Querying for Channel Update Events

Update

PreviousPostNextCreation

Last updated 2 months ago

Updating a channel will only succeed for a . The lowercase value of the channel name must remain the same.

Update a Sage channel

import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { useChannel } from '@sage-app/sdk/react';

interface ChannelUpdateInput {
  amounts: number[];           // payment amounts set to [0, 0]
  avatarHash?: string;
  bannerHash?: string;
  channelName: string;
  description: string;
  self: string;                // user's wallet address
  soulId: string;              // address of user's owned soul
}

...

const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
const { update } = useChannel();

...

const updateChannel = async (data: ChannelUpdateInput) => {
  const { ok, err, transaction } = await update(data);
    
  const { digest } = await signAndExecuteTransaction({
    transaction
  });
};

Error Codes

Channel Actions module

Code
Value
Meaning

370

EChannelNameMismatch

The lowercase value of the new channel name must match the lowercase value of the old channel name.

Channel Fees module

Code
Value
Meaning

370

EIncorrectCoinType

Custom payment type does not match configured custom payment coin.

371

EIncorrectCustomPayment

Incorrect custom payment value.

372

EIncorrectSuiPayment

Incorrect sui payment value.

Moderation module

Code
Value
Meaning

371

EIsNotModerator

User is not moderator of channel.

Querying for Channel Update Events

import { EventId, SuiClient, getFullnodeUrl } from '@mysten/sui/client';
import { SageClient } from '@sage-app/sdk/client';

...

interface QueryInput {
  cursor?: EventId;
}

const appId = '<YOUR_APP_ID>';
const network = 'mainnet' | 'testnet';
const suiClient = new SuiClient({ url: getFullnodeUrl(network) });

const sageClient = new SageClient({ appId, network, suiClient });

...

const pollChannelUpdates = async ({ cursor }) => {
  const {
    eventCount,
    events,
    hasNextPage,
    nextCursor
  } = await sageClient.queryChannelCreateEvents({ cursor }: QueryInput);
  
  // do something with events
  
  setTimeout(() => pollChannelUpdates({ cursor: nextCursor }), 5000);
};

In this case events will take the shape of an array of ChannelUpdateEvent:

interface ChannelUpdateEvent {
  avatarHash: string;
  bannerHash: string;
  channelKey: string;      // <= e.g. "sui-play" (unique value, always lowercase)
  channelName: string;     // <= e.g. "sui-PLAY" (display name)
  description: string;
  updatedAt: string;
}  
moderator