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
  • Create a channel post
  • Error Codes
  • Querying for New Channel Post Events

Post

PreviousModerationNextUpdate

Last updated 2 months ago

Creating a channel post will only succeed for a user that is a .

Create a channel post

In this case data, description, and title are expected to be a markdown string. This allows for formatting, creating links, and more without causing downstream security risks.

The SDK sanitizes inputs on entry, removing html tags and attributes, as well as escaping text.

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

interface ChannelPostInput {
  amounts: number[];           // payment amounts set to [0, 0]
  channelId: string;           // channel address
  data: string;                // markdown string input
  description: string;         // markdown string input
  self: string;                // user's wallet address
  soulId: string;              // address of user's owned soul
  title: string;               // markdown string input
}

...

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

...

const createChannelPost = async (data: ChannelPostInput) => {
  const { ok, err, transaction } = await post(data);
    
  const { digest } = await signAndExecuteTransaction({
    transaction
  });
};

Error Codes

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.

Membership module

Code
Value
Meaning

370

EIsNotMember

User is not member of channel.

Querying for New Channel Post Events

The query API in the SDK sanitizes input from data, description, and title. The contract is not able to sanitizes these values for the developer performantly so that responsibility is placed here.

Developers must ensure for themselves that `data`, `description`, and `title` are safe before they are used.

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 pollNewChannelPosts = async ({ cursor }) => {
  const {
    eventCount,
    events,
    hasNextPage,
    nextCursor
  } = await sageClient.queryChannelPostEvents({ cursor }: QueryInput);
  
  // do something with events
  
  setTimeout(() => pollNewChannelPosts({ cursor: nextCursor }), 5000);
};

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

interface ChannelPostCreatedEvent {
  id: string;              // post object address
  app: string;             // name of app where post was created (e.g. "sage")
  channelKey: string;      // <= e.g. "sui-play" (unique value, always lowercase)
  createdAt: string;
  createdBy: string;       // user's wallet address
  data: string;            // sanitized markdown string
  description: string;     // sanitized markdown string
  title: string;           // sanitized markdown string
}  
member of the channel