Posts, Replies & Likes
Public content, cursor, and status events.
Posts & Replies#
await (await social.publishPost('A post from my community', 0n)).wait();
await (await social.publishPost('This is a reply', postId)).wait();
const post = await social.post(postId);
const replies = await social.replies(postId, 0n, 20);parentId=0Create a top-level dynamic, and other values will reply to existing posts. The returned Post contains id, author, content, timestamp, parentId, likes, and replyCount.
Contents are 1–1120 UTF-8 bytes. Chinese usually takes up 3 bytes, emoji may take up 4 bytes. The official website also has a 280-character interface limit. Other projects can be limited according to their own display rules, but they cannot exceed the byte limit on the chain.
Cursor paging#
let cursor = 0n;
do {
const page = await social.posts(cursor, 20);
// Save page.posts and deduplicate by id.
cursor = page.nextCursor;
} while (cursor !== 0n);posts, authorPosts, repliesStarting from the latest, the first cursor=0, and returning nextCursor=0 indicates the end. The cursor is the position in the corresponding list, not the post ID. Cursors from different lists cannot be mixed. Adding a new post does not change the old position, but new content requires event push or re-requesting the latest page after the first page turn.
Like#
setLike(id, true)Like, setLike(id, false)Cancellation. Setting the same state as the current state will be rolled back. uselikedObtain the account status; enabled in the event indicates the status after setting, and each event should not simply be counted as plus 1.
Public data and application display#
Posts are public and permanently saved. The existing protocol does not have deletion and private post interfaces, nor does it have application ID or private channel fields. Application team can maintain tags, content selection and review status in their own indexes, which only affect their own display and will not delete on-chain content.
PostPublishedProvide author, post ID, parentId and body, time comes from block; LikeUpdatedProvide account and final like switch. The index is processed in the order of logIndex within the transaction to maintain the projection of replies and likes.