> For the complete documentation index, see [llms.txt](https://docs.clique.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clique.tech/clique-wallet/getting-started/sdk-integration.md).

# 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:

```bash
npm install clique-wallet-sdk
```

Or using yarn:

```bash
yarn add clique-wallet-sdk
```

For more information, visit the [Clique Wallet SDK on npm](https://www.npmjs.com/package/clique-wallet-sdk).

#### Basic Usage

**Initialize the SDK**

```javascript
import { CliqueWallet } from 'clique-wallet-sdk';

const wallet = new CliqueWallet({
  apiUrl: 'https://your-wallet-instance.com'
});
```

**Authenticate User**

```javascript
// Request verification code
await wallet.sendVerification({ email: 'user@example.com' });

// Complete login with verification code
const user = await wallet.login({
  type: 'Email',
  data: {
    email: 'user@example.com',
    code: '123456'
  }
});
```

**Get Wallet Addresses**

```javascript
// 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**

```javascript
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:**

```javascript
await wallet.sendVerification({ email: 'user@example.com' });
// or
await wallet.sendVerification({ phone: '+1234567890' });
```

**Social OAuth:**

```javascript
// 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:**

```javascript
// 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:

```javascript
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
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clique.tech/clique-wallet/getting-started/sdk-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
