import { useComposeCast } from '@coinbase/onchainkit/minikit';

export default function ShareButton() {
  const { composeCast } = useComposeCast();

  const handleShare = () => {
    composeCast({
      text: 'Just completed the daily puzzle! 🧩'
    });
  };

  return (
    <button onClick={handleShare}>
      Share Achievement
    </button>
  );
}
Defined in @coinbase/onchainkit
Opens the native cast composer with prefilled text and embeds. Essential for viral growth and social sharing within Mini Apps.

Returns

composeCast
(params: ComposeCastParams) => void
Function that opens the cast composer with specified content.
import { useComposeCast } from '@coinbase/onchainkit/minikit';

export default function ShareButton() {
  const { composeCast } = useComposeCast();

  const handleShare = () => {
    composeCast({
      text: 'Just completed the daily puzzle! 🧩'
    });
  };

  return (
    <button onClick={handleShare}>
      Share Achievement
    </button>
  );
}

Strategic Sharing Patterns

Achievement Moments

Share at moments of user accomplishment:
examples/AchievementMoments.tsx
// After quiz completion
composeCast({
  text: "I'm a Ravenclaw! 🦅 What house are you?",
  embeds: [quizUrl]
});

// After NFT mint
composeCast({
  text: "Just minted my first collectible! 🎨",
  embeds: [mintUrl, nftImageUrl]
});

// After game milestone
composeCast({
  text: "Finally beat level 50! This game is addictive 🎮",
  embeds: [gameUrl]
});

Viral Growth Mechanics

Design shares that encourage interaction:
examples/ViralGrowthMechanics.tsx
// Challenge pattern
composeCast({
  text: "Beat my time of 2:34 if you can! ⏱️",
  embeds: [challengeUrl]
});

// Social proof pattern  
composeCast({
  text: "Join 50,000+ players already playing!",
  embeds: [gameUrl]
});

// FOMO pattern
composeCast({
  text: "Limited edition drop ends in 2 hours! 🔥",
  embeds: [dropUrl]
});

Content Personalization

Customize shares based on user activity:
examples/ContentPersonalization.tsx
import { useMiniKit, useComposeCast } from '@coinbase/onchainkit/minikit';

export default function PersonalizedShare() {
  const { context } = useMiniKit();
  const { composeCast } = useComposeCast();
  
  const sharePersonalized = (achievement) => {
    const isNewUser = !context.client.added;
    
    const text = isNewUser 
      ? `Just discovered this amazing ${achievement.category} app!`
      : `Another ${achievement.type} completed! ${achievement.streak} day streak 🔥`;
      
    composeCast({
      text,
      embeds: [window.location.href]
    });
  };

  return (
    <button onClick={() => sharePersonalized(userAchievement)}>
      Share Progress
    </button>
  );
}

Best Practices

Text Content

  • Keep it concise: Farcaster has character limits
  • Include emotional context: Use emojis and excitement
  • Add clear value: Explain why others should care
  • Include call-to-action: “Try it yourself”, “Beat my score”

Embed Strategy

  • Always include your app URL for discoverability
  • Add relevant media: Images, videos, other content
  • Test embed rendering: Ensure metadata displays correctly

Timing Optimization

  • Post-achievement: When users feel accomplished
  • Social moments: When friends are likely online
  • Value demonstration: After showing app benefits
  • Avoid interruption: Don’t break user flow
The composer opens in a native overlay or new window depending on the client. Users can modify the text before posting, so don’t rely on exact text for tracking. Use URL parameters or unique embeds for attribution tracking.
useComposeCast is one of the most powerful hooks for viral growth. Strategic implementation of sharing at the right moments can significantly increase your Mini App’s reach and user acquisition.