Quick Start
Get Started with Crefy Connect
Follow this guide to integrate Crefy Connect into your application in under 10 minutes.
Prerequisites
What you'll need before getting started
Development Environment
- Node.js 16+ installed
- npm or yarn package manager
- React 18+ or Next.js 13+
- TypeScript (recommended)
1
Install the SDKAdd Crefy Connect to your project
Using npm
npm install @crefy/connect-sdk
Using yarn
yarn add @crefy/connect-sdk
The SDK includes TypeScript definitions and works with both JavaScript and TypeScript projects.
2
Configure EnvironmentSet up your environment variables and configuration
Environment Variables
.env.localbash
# Crefy Connect Configuration
NEXT_PUBLIC_CREFY_APP_ID=your_app_id_here
NEXT_PUBLIC_CREFY_ENVIRONMENT=sandbox # or 'production'
CREFY_API_SECRET=your_api_secret_here
# Optional: Custom configuration
NEXT_PUBLIC_CREFY_REDIRECT_URI=http://localhost:3000/auth/callback
NEXT_PUBLIC_CREFY_CHAIN_ID=1 # Ethereum mainnet
Never expose your API secret in client-side code. Use it only in server-side operations.
3
Initialize the SDKSet up the Crefy Connect client in your application
Create SDK Instance
lib/crefy.jsjavascript
import { CrefyConnect } from '@crefy/connect-sdk'
// Initialize Crefy Connect
export const crefy = new CrefyConnect({
appId: process.env.NEXT_PUBLIC_CREFY_APP_ID,
environment: process.env.NEXT_PUBLIC_CREFY_ENVIRONMENT,
chainId: parseInt(process.env.NEXT_PUBLIC_CREFY_CHAIN_ID || '1'),
redirectUri: process.env.NEXT_PUBLIC_CREFY_REDIRECT_URI
})
// Optional: Configure additional settings
crefy.configure({
theme: 'dark',
socialProviders: ['google', 'twitter', 'discord'],
enableAnalytics: true
})
React Hook (Optional)
hooks/useCrefy.jsjavascript
import { useState, useEffect } from 'react'
import { crefy } from '../lib/crefy'
export function useCrefy() {
const [wallet, setWallet] = useState(null)
const [isConnecting, setIsConnecting] = useState(false)
const [error, setError] = useState(null)
const connectWallet = async (provider = 'google') => {
try {
setIsConnecting(true)
setError(null)
const connectedWallet = await crefy.connectWallet({
provider,
method: 'social'
})
setWallet(connectedWallet)
return connectedWallet
} catch (err) {
setError(err.message)
throw err
} finally {
setIsConnecting(false)
}
}
const disconnect = async () => {
await crefy.disconnect()
setWallet(null)
}
return {
wallet,
isConnecting,
error,
connectWallet,
disconnect
}
}
4
Connect WalletImplement wallet connection in your React component
Basic Connection Component
components/WalletConnect.jsxjavascript
import { useCrefy } from '../hooks/useCrefy'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
export function WalletConnect() {
const { wallet, isConnecting, error, connectWallet, disconnect } = useCrefy()
if (wallet) {
return (
<Card>
<CardHeader>
<CardTitle>Wallet Connected</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2">
<p><strong>Address:</strong> {wallet.address}</p>
<p><strong>Provider:</strong> {wallet.provider}</p>
<p><strong>Balance:</strong> {wallet.balance} ETH</p>
<Button onClick={disconnect} variant="outline">
Disconnect
</Button>
</div>
</CardContent>
</Card>
)
}
return (
<Card>
<CardHeader>
<CardTitle>Connect Your Wallet</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
<Button
onClick={() => connectWallet('google')}
disabled={isConnecting}
className="w-full"
>
{isConnecting ? 'Connecting...' : 'Connect with Google'}
</Button>
<Button
onClick={() => connectWallet('twitter')}
disabled={isConnecting}
variant="outline"
className="w-full"
>
Connect with Twitter
</Button>
<Button
onClick={() => connectWallet('discord')}
disabled={isConnecting}
variant="outline"
className="w-full"
>
Connect with Discord
</Button>
{error && (
<p className="text-destructive text-sm">{error}</p>
)}
</div>
</CardContent>
</Card>
)
}
5
Test Your IntegrationVerify everything is working correctly
Add to Your App
pages/index.js or app/page.jsjavascript
import { WalletConnect } from '../components/WalletConnect'
export default function Home() {
return (
<div className="container mx-auto p-8">
<h1 className="text-2xl font-bold mb-8">My Web3 App</h1>
<WalletConnect />
</div>
)
}
Run Your Application
npm run dev
Visit
http://localhost:3000
to test your wallet connection. Make sure your redirect URI matches your development URL.🎉 Congratulations!
You've successfully integrated Crefy Connect. Here's what to explore next:
Common Issues
Redirect URI Mismatch
Ensure your redirect URI in the dashboard matches your development URL exactly.
Environment Variables Not Loading
Restart your development server after adding environment variables.
CORS Issues
Add your domain to the allowed origins in your Crefy dashboard.
Need Help?
Our team is here to help you succeed with your integration