SDK Integration
This guide helps developers integrate Clique Wallet into their applications using the official SDK. The Clique Wallet SDK is available as an npm package and provides a convenient way to interact with Clique Wallet's API.
Prerequisites
Access to a Clique Wallet instance
The Clique Wallet API endpoint URL
Node.js 16+ or a modern JavaScript environment
Installation
Install the Clique Wallet SDK using npm:
npm install clique-wallet-sdkOr using yarn:
yarn add clique-wallet-sdkFor more information, visit the Clique Wallet SDK on npm.
Basic Usage
Initialize the SDK
import { CliqueWallet } from 'clique-wallet-sdk';
const wallet = new CliqueWallet({
apiUrl: 'https://your-wallet-instance.com'
});Authenticate User
// Request verification code
await wallet.sendVerification({ email: '[email protected]' });
// Complete login with verification code
const user = await wallet.login({
type: 'Email',
data: {
email: '[email protected]',
code: '123456'
}
});Get Wallet Addresses
// Get current session and wallet information
const session = await wallet.getSession();
// Access wallet addresses
const ethereumWallet = session.wallets.find(w => w.network === 'Ethereum');
const solanaWallet = session.wallets.find(w => w.network === 'Solana');Sign Transaction
const signature = await wallet.sign({
address: '0x...',
network: 'Ethereum',
message: '0x...',
need_check: true
});Authentication Methods
The SDK supports all authentication methods available in Clique Wallet:
Email/Phone Verification:
await wallet.sendVerification({ email: '[email protected]' });
// or
await wallet.sendVerification({ phone: '+1234567890' });Social OAuth:
// Initialize OAuth flow
const oauthUrl = await wallet.oauth.init({
provider: 'google',
redirectUri: 'https://yourapp.com/callback'
});
// After OAuth callback, complete login
await wallet.login({
type: 'GoogleOAuth',
data: { state, code, code_verifier }
});External Wallet Connection:
// Get challenge
const challenge = await wallet.getChallenge({
method: 'metamask',
id: '0x...'
});
// After user signs, complete login
await wallet.login({
type: 'MetaMask',
data: { wallet_address, challenge, signature }
});Error Handling
The SDK provides structured error handling:
try {
const user = await wallet.login({ /* ... */ });
} catch (error) {
if (error.status === 401) {
// Handle authentication error
} else if (error.status === 400) {
// Handle bad request
} else {
// Handle other errors
}
}Last updated