Turn any text into a payment link. One click, instant x402 payments.
<p>
Enjoyed this article?
<PaymentLink to="0x..." amount="0.50">
Buy me a coffee ☕
</PaymentLink>
</p>- 💸 One-Click Payments - Text links that trigger instant payments
- 🎨 Looks Like Text - Seamlessly integrates into content
- ✅ Confirmation Modal - Shows payment details before executing
- 🔗 Shareable Links - Generate payment URLs to share anywhere
- 🚀 Zero Navigation - Payments happen inline, no page changes
- 🔐 Built on Connect - Uses @onchainfi/connect for wallet + payments
npm install @onchainfi/hyperlink @onchainfi/connectPrerequisites: Requires @onchainfi/connect to be installed and configured.
import { OnchainConnect } from '@onchainfi/connect';
<OnchainConnect privyAppId="..." onchainApiKey="...">
<App />
</OnchainConnect>import { PaymentLink } from '@onchainfi/hyperlink';
export default function BlogPost() {
return (
<article>
<h1>My Article</h1>
<p>Great content here...</p>
<p>
Enjoyed this?
<PaymentLink
to="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
amount="0.50"
>
Buy me a coffee ☕
</PaymentLink>
</p>
</article>
);
}That's it! Users click the link, see a confirmation modal, approve, and payment completes - all without leaving the page.
A text link that triggers an inline payment.
Props:
{
// Required
to: string; // Recipient address
amount: string; // Amount in token units
children: ReactNode; // Link text
// Optional
network?: string; // Default: 'base'
token?: string; // Default: 'USDC'
memo?: string; // Payment description
priority?: 'speed' | 'cost' | 'reliability' | 'balanced';
className?: string; // Custom link styling
// Callbacks
onSuccess?: (txHash: string) => void;
onError?: (error: Error) => void;
// Behavior
confirmMessage?: string; // Custom confirmation text
skipConfirm?: boolean; // Skip modal, pay immediately
disabled?: boolean;
}Example:
<PaymentLink
to="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
amount="1.00"
memo="Premium article access"
onSuccess={(txHash) => unlockContent()}
>
Unlock for $1
</PaymentLink>Generate shareable payment URLs.
import { createPaymentLink } from '@onchainfi/hyperlink';
const link = createPaymentLink({
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
amount: '0.50',
memo: 'Coffee donation',
baseUrl: 'https://myblog.com/donate'
});
// Returns: https://myblog.com/donate?x402=eyJ0b...Options:
{
to: string;
amount: string;
network?: string;
token?: string;
memo?: string;
priority?: string;
baseUrl?: string; // URL to append payment data to
useHash?: boolean; // Use hash fragment instead of query param
}function PremiumArticle() {
const [unlocked, setUnlocked] = useState(false);
if (!unlocked) {
return (
<div>
<h2>Premium Content</h2>
<p>
<PaymentLink
to="0x..."
amount="0.10"
onSuccess={() => setUnlocked(true)}
>
Pay $0.10 to unlock
</PaymentLink>
</p>
</div>
);
}
return <Article />;
}function CreatorProfile() {
return (
<div>
<h1>@creator</h1>
<p>
Support my work:
<PaymentLink to="0x..." amount="1.00">$1</PaymentLink> |
<PaymentLink to="0x..." amount="5.00">$5</PaymentLink> |
<PaymentLink to="0x..." amount="10.00">$10</PaymentLink>
</p>
</div>
);
}<footer>
<p>
This site is free. If you found it helpful, consider
<PaymentLink to="0x..." amount="0.50" memo="Site donation">
donating
</PaymentLink>
to keep it running.
</p>
</footer>function ShareDonationLink() {
const link = createPaymentLink({
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
amount: '0.50',
memo: 'Support the project',
baseUrl: 'https://myproject.com'
});
return (
<button onClick={() => navigator.clipboard.writeText(link)}>
Copy Donation Link
</button>
);
}PaymentLink accepts className for custom styling:
<PaymentLink
to="0x..."
amount="0.10"
className="font-bold text-blue-500 hover:text-blue-400"
>
Custom styled link
</PaymentLink>Default style: Purple link with underline (matches Onchain aesthetic)
<PaymentLink
to="0x..."
amount="0.01"
skipConfirm={true}
>
Quick tip $0.01
</PaymentLink><PaymentLink
to="0x..."
amount="5.00"
confirmMessage="This will unlock premium features for 30 days"
>
Upgrade to Premium
</PaymentLink><PaymentLink
to="0x..."
amount="0.50"
onSuccess={(txHash) => {
console.log('Payment sent!', txHash);
// Unlock content, track analytics, etc.
}}
onError={(error) => {
console.error('Payment failed:', error);
// Show error message, log for support
}}
>
Pay here
</PaymentLink>- User clicks the payment link
- Modal shows payment details (amount, recipient, network)
- User confirms
- Connect wallet handles signature + payment
- Payment routes through Onchain aggregator
- Success! User stays on the same page
All payments flow through api.onchain.fi - same infrastructure as Connect.
- ✅
@onchainfi/connectinstalled and configured - ✅ User has Connect wallet connected
- ✅ Sufficient token balance
Fully typed:
import type {
PaymentLinkProps,
PaymentLinkData,
CreatePaymentLinkOptions
} from '@onchainfi/hyperlink';See examples/ folder for complete working examples:
- Content paywall
- Tip buttons
- Donation links
- Shopping cart integration
AGPL-3.0
- Email: dev@onchain.fi
- GitHub Issues: github.com/onchainfi/hyperlink/issues