Create
Creating a channel will only succeed for a Sui address that has an associated Sage user.
Create a new Sage channel
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
});
};
Error Codes
Authentication module
Code
Value
Meaning
370
ENotAuthenticated
User soul object does not exist, is the wrong type, or not owned by the wallet.
Channel module
Code
Value
Meaning
370
EInvalidChannelDescription
Description must be less than 370 characters.
371
EInvalidChannelName
Name must be a-z, A-Z, 0-9, dash (NOT in beginning or end), and between 3 - 21 characters.
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.
Querying for New Channel 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 pollNewChannels = async ({ cursor }) => {
const {
eventCount,
events,
hasNextPage,
nextCursor
} = await sageClient.queryChannelCreateEvents({ cursor }: QueryInput);
// do something with events
setTimeout(() => pollNewChannels({ cursor: nextCursor }), 5000);
};
In this case events will take the shape of an array of ChannelCreateEvent:
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;
}
Last updated