useGenerateReferralLink()
This hook is the entry point to Refract’s powerful viral growth engine. It generates a personalized dApp link for the current user that, when shared, automatically tracks referrals, builds your social graph, and distributes any configured rewards.
Usage
The hook returns a function that you can call to get the referral link.
import { useGenerateReferralLink } from '@refract-network/securesign-sdk/react'; // ::TODO: confirm package
import { useState } from 'react';
export function ReferralLinkGenerator() {
const { generateLink, isGenerating } = useGenerateReferralLink();
const [referralLink, setReferralLink] = useState('');
const [error, setError] = useState('');
const handleClick = async () => {
try {
setError('');
const link = await generateLink();
setReferralLink(link);
} catch (err: any) {
setError(err.message);
}
};
return (
<div>
<button onClick={handleClick} disabled={isGenerating}>
{isGenerating ? 'Generating...' : 'Generate My Referral Link'}
</button>
{referralLink && (
<div style={{ marginTop: '1rem' }}>
<p>Your link is ready! Share it with friends:</p>
<input type="text" readOnly value={referralLink} style={{ width: '300px' }} />
<button onClick={() => navigator.clipboard.writeText(referralLink)}>
Copy
</button>
</div>
)}
{error && <div style={{ color: 'red', marginTop: '1rem' }}>Error: {error}</div>}
</div>
);
}
Return Value
{
generateLink: () => Promise<string>;
isGenerating: boolean;
error: Error | null;
}
generateLink()
Function
- Arguments: None. The hook automatically uses the connected user’s
userId
and your dApp’s appId
(from the provider configuration).
- Returns: A
Promise<string>
that resolves to the full referral URL (e.g., https://refract.network/app?appId=...&referrerId=...
).