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
  • Join a Sage channel
  • Error Codes
  • Leave a Sage channel
  • Error Codes
  • Querying for Channel Membership Events
  1. Channel

Membership

PreviousCreateNextModeration

Last updated 2 months ago

Following a channel will only succeed for a Sui address that has Unfollowing will only succeed if the user is already following the channel.

Join a Sage channel

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

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

...

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

...

const joinChannel = async (data: ChannelJoinInput) => {
  const { ok, err, transaction } = await join(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 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.

Leave a Sage channel

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

interface ChannelLeaveInput {
  amounts: number[];           // payment amounts set to [0, 0]
  channelId: string;           // channel address
  self: string;                // user's wallet address
}

...

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

...

const leaveChannel = async (data: ChannelLeaveInput) => {
  const { ok, err, transaction } = await leave(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.

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

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

interface ChannelMemberbershipEvent {
  accountType: "OBJECT" | "WALLET";
  channelKey: string;              // <= e.g. "sui-play" (unique value, lowercase)
  message: "JOIN" | "LEAVE";
  updatedAt: string;
  user: string;                    // <= user's address
}  
an associated Sage user.