Quickstart
Add LayerCover insurance to your dApp in under 5 minutes
Get LayerCover running in your React dApp in three steps.
1. Install
npm install @layercover/sdk ethers viem wagmi @mui/material @emotion/react @emotion/styled
2. Add the CoverButton
import { CoverButton } from '@layercover/sdk/react'; import { ViemAdapter } from '@layercover/sdk'; import { useWalletClient } from 'wagmi'; function ProtocolPage() { const { data: walletClient } = useWalletClient(); const signer = walletClient ? ViemAdapter.fromWalletClient(walletClient) : undefined; return ( <CoverButton signer={signer} poolId={1} /> ); }
That's it! The button renders a styled "Cover" button. When clicked, it opens a complete purchase modal with quote fetching, duration selection, and transaction execution.
Live Example
// App.tsx - Full working example import { CoverButton } from '@layercover/sdk/react'; import { ViemAdapter } from '@layercover/sdk'; import { useWalletClient } from 'wagmi'; export default function App() { const { data: walletClient } = useWalletClient(); const signer = walletClient ? ViemAdapter.fromWalletClient(walletClient) : undefined; return ( <div style={{ padding: '2rem', textAlign: 'center' }}> <h2>My DeFi Protocol</h2> <p>Your deposits are protected by LayerCover</p> <CoverButton signer={signer} poolId={1} buttonText="Get Protected" onSuccess={() => alert('Coverage purchased!')} /> </div> ); }
3. What Happens When a User Clicks
Full CoverButton Props
| Prop | Type | Required | Description |
|---|---|---|---|
signer | Signer | ✅ | ethers v6 signer |
poolId | number | ✅ | Pool ID for the coverage pool |
availableBalance | number | User's token balance (display only) | |
onSuccess | () => void | Callback after successful purchase | |
referralCode | string | Referral code as bytes32 hex (0x + 64 hex chars) | |
buttonText | string | Button label (default: "Cover") | |
theme | Theme | Custom theme overrides |
Example with All Options
<CoverButton signer={signer} poolId={1} availableBalance={userBalance} referralCode={encodeBytes32String('YOUR_REFERRAL_CODE')} onSuccess={() => { toast.success('Coverage purchased!'); refetchPositions(); }} buttonText="Get Protected" theme={customTheme} />
Referral Integration
Attach a referral code when preparing a purchase. The default suggested reward is often 5%, but the live referral rate is deployment-configurable and capped at 10%:
import { encodeBytes32String } from 'ethers'; <CoverButton signer={signer} poolId={1} referralCode={encodeBytes32String('YOUR_CODE')} />
Partner Benefits: Register your referral code at app.layercover.com to start earning from referrals. Rewards become claimable once the protocol funds them through the referral ledger.
Next Steps
1️⃣
User clicks **"Cover"**
2️⃣
Modal fetches live quotes
3️⃣
User selects amount & duration
4️⃣
Approve + purchase in one flow