Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.sageprotocol.xyz/llms.txt

Use this file to discover all available pages before exploring further.

Likes signal appreciation and enhance content visibility, triggering incremental rewards in Sage Protocol. React Hook Example for Liking Posts:
import { usePost } from '@sageprotocol/sdk/react';
import { useWallet } from '@suiet/wallet-kit';

function LikePost({ authorSharedUserId, postId, ownedUserId }) {
  const { like } = usePost();
  const { account, signAndExecuteTransaction } = useWallet();

  async function handleLike() {
    const result = await like({
      amounts: [0, 0],                         // Required protocol fees
      appId: 'your-app-id',                    // Explicitly required application ID
      network: 'testnet',                      // 'testnet' or 'mainnet'
      authorSharedUserId,                      // Original post author's shared user ID
      postId,                                  // ID of the post to like
      ownedUserId,                             // Liker’s owned user ID
      self: account.address                    // Liker’s wallet address
    });

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

  return <button onClick={handleLike}>Like Post</button>;
}

export default LikePost;
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 likePost(authorSharedUserId, postId, ownedUserId, walletAddress) {
  const result = await sageClient.likePost({
    amounts: [0, 0],                        // Required protocol fees
    authorSharedUserId,                     // Original post author's shared user ID
    postId,                                 // ID of the post to like
    ownedUserId,                            // Liker’s owned user ID
    self: walletAddress                     // Liker’s wallet address
  });

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

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

Important Notes

  • Required Parameters: Inclusion of amounts, appId, network, authorSharedUserId, postId, ownedUserId, and self.
  • Reward Mechanism: Likes enhance content visibility and trigger incremental rewards.
  • Transaction Execution: All transactions must be signed and executed via the user’s connected wallets.