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 new Sage user
  • Error Codes
  • Querying for New User Events
  1. User

Create

A Sui address must run this user creation step first before they are able to interact with any of the other Sage contracts.

However, the user creation step will be limited at first to requiring an invite code from another Sage user. At a later date invitations will be an optional step.

Create a new Sage user

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

interface UserCreateInput {
  amounts: number[];           // payment amounts set to [0, 0]
  avatarHash?: string;
  bannerHash?: string;
  description: string;
  inviteCode?: string;
  inviteKey?: string;
  name: string;
  self: string;                // user's wallet address
}

...

const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
const { create } = useUser();

...

const createUser = async (data: UserCreateInput) => {
  const { ok, err, transaction } = create(data);
    
  const { digest } = await signAndExecuteTransaction({
    transaction
  });
};

Error Codes

User module

Code
Value
Meaning

370

EInvalidDescription

Description is more than 370 characters.

371

EInvalidUsername

Name must be a-z, A-Z, 0-9, dash (NOT in beginning or end), and between 3 - 20 characters.

User Actions module

Code
Value
Meaning

370

ENoInvite

No invite code was used and invites are required.

371

ENotInvited

The invite code was invalid.

User 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.

User Invites module

Code
Value
Meaning

371

EInviteDoesNotExist

The invite code used does not exist.

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

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

interface UserCreateEvent {
  id: string;              // user object address
  avatarHash: string;
  bannerHash: string;
  createdAt: string;
  description: string;
  owner: string;           // user' wallet address
  referredBy?: string;     // referrer's user object address
  soul: string;            // user's soul object address
  userKey: string;         // e.g. "matrix-rick" (unique value, lowercase)
  userName: string;        // e.g. "MaTriX-riCK" (display name)
}  
PreviousLikeNextMembership

Last updated 2 months ago