import { useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { useChannel } from '@sage-app/sdk/react';
interface ChannelCreateInput {
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 { create } = useChannel();
...
const createChannel = async (data: ChannelCreateInput) => {
const { ok, err, transaction } = await create(data);
const { digest } = await signAndExecuteTransaction({
transaction
});
};
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 pollNewChannels = async ({ cursor }) => {
const {
eventCount,
events,
hasNextPage,
nextCursor
} = await sageClient.queryChannelCreateEvents({ cursor }: QueryInput);
// do something with events
setTimeout(() => pollNewChannels({ cursor: nextCursor }), 5000);
};
interface ChannelCreateEvent {
id: string; // channel object address
avatarHash: string;
bannerHash: string;
channelKey: string; // <= e.g. "sui-play" (unique value, always lowercase)
channelName: string; // <= e.g. "sui-PLAY" (display name)
createdAt: string;
createdBy: string; // user's wallet address
description: string;
}