Skip to main content
Users can bookmark posts explicitly to easily revisit preferred content.

Adding a Favorite Post

React Hook Example for Adding a Favorite Post:
import { useUser } from '@sageprotocol/sdk/react';
import { useWallet } from '@suiet/wallet-kit';

function FavoritePost({ ownedUserId, authorSharedUserId, postId }) {
  const { addFavoritePost } = useUser();
  const { account, signAndExecuteTransaction } = useWallet();

  async function handleFavorite() {
    const result = await addFavoritePost({
      appId: 'your-app-id',                     // Required application ID
      network: 'testnet',                       // 'testnet' or 'mainnet'
      authorSharedUserId,                       // Author's shared user ID
      postId,                                   // Post ID to bookmark
      ownedUserId                               // Your owned user ID
    });

    if (result.ok) {
      await signAndExecuteTransaction({ transaction: result.transaction });
      console.log("Post bookmarked successfully!");
    } else {
      console.error("Error bookmarking post:", result.err);
    }
  }

  return <button onClick={handleFavorite}>Bookmark Post</button>;
}

export default FavoritePost;
import { SageClient } from '@sageprotocol/sdk';

const sageClient = new SageClient({
  appId: 'your-app-id',                      // Required application ID
  channelRegistryId: 'your-registry-id',     // Required channel registry ID
  network: 'testnet'                         // 'testnet' or 'mainnet'
});

await sageClient.initialize();

async function addFavoritePost(ownedUserId, authorSharedUserId, postId) {
  const result = await sageClient.addFavoritePost({
    authorSharedUserId,                      // Author's shared user ID
    postId,                                  // Post ID to bookmark
    ownedUserId                              // Your owned user ID
  });

  if (result.ok) {
    await signAndExecuteTransaction({ transaction: result.transaction });
    console.log("Post bookmarked successfully!");
  } else {
    console.error("Error bookmarking post:", result.err);
  }
}

addFavoritePost('your-owned-user-id', 'author-shared-user-id', 'target-post-id');

Removing a Favorited Post

React Hook Example for Removing a Favorite Post:
import { useUser } from '@sageprotocol/sdk/react';
import { useWallet } from '@suiet/wallet-kit';

function RemoveFavoritePost({ ownedUserId, postId }) {
  const { removeFavoritePost } = useUser();
  const { account, signAndExecuteTransaction } = useWallet();

  async function handleRemoveFavorite() {
    const result = await removeFavoritePost({
      appId: 'your-app-id',                      // Required application ID
      network: 'testnet',                        // 'testnet' or 'mainnet'
      postId,                                    // Post ID to remove from bookmarks
      ownedUserId                                // Your owned user ID
    });

    if (result.ok) {
      await signAndExecuteTransaction({ transaction: result.transaction });
      console.log("Post removed from bookmarks successfully!");
    } else {
      console.error("Error removing bookmark:", result.err);
    }
  }

  return <button onClick={handleRemoveFavorite}>Remove Bookmark</button>;
}

export default RemoveFavoritePost;
import { SageClient } from '@sageprotocol/sdk';

const sageClient = new SageClient({
  appId: 'your-app-id',                     // Required application ID
  channelRegistryId: 'your-registry-id',    // Required channel registry ID
  network: 'testnet'                        // 'testnet' or 'mainnet'
});

await sageClient.initialize();

async function removeFavoritePost(ownedUserId, postId) {
  const result = await sageClient.removeFavoritePost({
    postId,                                 // Post ID to remove from bookmarks
    ownedUserId                             // Your owned user ID
  });

  if (result.ok) {
    await signAndExecuteTransaction({ transaction: result.transaction });
    console.log("Post removed from bookmarks successfully!");
  } else {
    console.error("Error removing bookmark:", result.err);
  }
}

removeFavoritePost('your-owned-user-id', 'target-post-id');

Important Notes

  • Required Parameters: Explicitly include appId, network, authorSharedUserId, postId, and ownedUserId for adding favorites. Removing favorites requires appId, network, postId, and ownedUserId.
  • Explicit Transaction Signing: Transactions must explicitly be signed and executed via the user’s wallet.