# Creating Wallets

In order to get wallets, please ensure that you have [registered and installed the Caishen SDK](/registration.md).

With the Caishen SDK, you can create wallets for:

* EVM
* Bitcoin
* Solana
* SUI
* XRP

{% hint style="info" %}
All Caishen wallets come with support for crosschain swaps and sending&#x20;
{% endhint %}

<figure><img src="/files/SUtLLc2g3DVtQevPGoaM" alt=""><figcaption><p>It's this easy to create your multichain wallets</p></figcaption></figure>

#### 🔍 Get Wallet Info

> ⚠️ The `privateKey` is only returned if `allowPrivateKeyAccess` is enabled in your developer dashboard.\
> You do **not** need to send the private key back to the server. All you need is `{ account, chainType }`.

**📥 Parameters**

| Name        | Type   | Required | Description                                  |
| ----------- | ------ | -------- | -------------------------------------------- |
| `chainType` | string | ✅        | Blockchain type (`ETHEREUM`, `SOLANA`, etc.) |
| `chainId`   | number | ❌        | Optional chain ID (e.g., 1 for Ethereum)     |
| `account`   | number | ✅        | Account index or identifier                  |

**✅ Supported chainTypes:**

* `BITCOIN`, `SOLANA`, `ETHEREUM`, `SUI`, `APTOS`, `TON`
* `TRON`, `NEAR`, `XRP`, `CARDANO`, `COSMOS`

***

**📘 Example**

```
const wallet = await sdk.crypto.getWallet({
  chainType: 'ETHEREUM',
  chainId: 1,
  account: 0,
});
```

**📚 Type: `IWalletAccount`**

```
interface IWalletAccount {
  address: string;
  chainType: string;
  account: number;
  publicKey: string;
  privateKey?: string; // Only returned if access is enabled in the dashboard
}
```

<figure><img src="/files/iIqgRX4b39Ws7IElaPfW" alt=""><figcaption><p>Copy your Project Key </p></figcaption></figure>

<details>

<summary>Example 1: Creating Wallets on EVM, Bitcoin, Solana, SUI &#x26; XRP</summary>

```
const { CaishenSDK } = require('@caishen/sdk');
const jwt = require('jsonwebtoken');
require('dotenv').config();

// 👤 One user
const userId = 'user-123'; // You can change this

// 🌐 Supported chains
const chains = [
  { name: 'Ethereum', chainType: 'ETHEREUM', chainId: 1 },
  { name: 'Solana', chainType: 'SOLANA', chainId: 101 },
  { name: 'Bitcoin', chainType: 'BITCOIN', chainId: 0 },
  { name: 'Sui', chainType: 'SUI', chainId: 1 },
  { name: 'XRP', chainType: 'XRP', chainId: 1 },
];

(async () => {
  try {
    const token = jwt.sign({ id: userId }, process.env.CAISHEN_PROJECT_SECRET);

    const sdk = new CaishenSDK({ projectKey: process.env.CAISHEN_PROJECT_KEY });
    await sdk.connectAsUser({
      provider: 'custom',
      token,
    });

    console.log(`✅ Connected as ${userId}\n`);

    for (const chain of chains) {
      try {
        const wallet = await sdk.crypto.getWallet({
          chainType: chain.chainType,
          chainId: chain.chainId,
          account: 0,
        });
        console.log(`✅ ${chain.name} Wallet:\n`, wallet, '\n');
      } catch (err) {
        console.error(`❌ Failed to create ${chain.name} wallet: ${err.message}\n`);
      }
    }
  } catch (err) {
    console.error('❌ Failed to connect user:', err.message);
  }
})();

```

</details>

<details>

<summary>Example 2: Creating Multiple Wallets for a Single User</summary>

```
const { CaishenSDK } = require('@caishen/sdk');
const jwt = require('jsonwebtoken');
require('dotenv').config();

// 👤 One user ID
const userId = 'user-123';

(async () => {
  try {
    // 🔐 Create JWT for this user
    const token = jwt.sign({ id: userId }, process.env.CAISHEN_PROJECT_SECRET);

    // 🔌 Create SDK instance + connect as user once
    const sdk = new CaishenSDK({ projectKey: process.env.CAISHEN_PROJECT_KEY });
    await sdk.connectAsUser({
      provider: 'custom',
      token,
    });

    // 🔁 Create 10 wallets (account 0 → 9)
    for (let i = 0; i < 10; i++) {
      try {
        const wallet = await sdk.crypto.getWallet({
          chainType: 'ETHEREUM',
          chainId: 1,
          account: i,
        });
        console.log(`✅ Wallet #${i} for ${userId}:`, wallet);
      } catch (err) {
        console.error(`❌ Failed to create wallet #${i}:`, err.message);
      }
    }
  } catch (err) {
    console.error(`❌ Failed to connect user:`, err.message);
  }
})();

```

</details>

<details>

<summary>Example 3: Creating EVM Wallets for 10 Users</summary>

```
const { CaishenSDK } = require('@caishen/sdk');
const jwt = require('jsonwebtoken');
require('dotenv').config();

// 🔁 Generate 10 user IDs
const users = Array.from({ length: 10 }, (_, i) => `user-${i + 1}`);

(async () => {
  for (const userId of users) {
    // Wrap the logic inside a try/catch for this user
    try {
      // 🔐 Create JWT
      const token = jwt.sign({ id: userId }, process.env.CAISHEN_PROJECT_SECRET);

      // 🆕 New SDK instance for each user
      const sdk = new CaishenSDK({ projectKey: process.env.CAISHEN_PROJECT_KEY });

      // 🚪 Connect user
      await sdk.connectAsUser({
        provider: 'custom',
        token,
      });

      // 👛 Create Ethereum wallet
      const wallet = await sdk.crypto.getWallet({
        chainType: 'ETHEREUM',
        chainId: 1,
        account: 0,
      });

      console.log(`✅ Wallet for ${userId}:`);
      console.log(`   Address: ${wallet.address}`);
      console.log(`   Public Key: ${wallet.publicKey}\n`);

    } catch (err) {
      console.error(`❌ Failed for ${userId}: ${err.message}\n`);
    }
  }
})();

```

</details>

<details>

<summary>Example 4: Creating EVM Wallets for 10 Users</summary>

```
const { CaishenSDK } = require('@caishen/sdk');
const jwt = require('jsonwebtoken');
require('dotenv').config();

// 🔁 Generate 10 user IDs
const users = Array.from({ length: 10 }, (_, i) => `user-${i + 1}`);

(async () => {
  for (const userId of users) {
    // Wrap the logic inside a try/catch for this user
    try {
      // 🔐 Create JWT
      const token = jwt.sign({ id: userId }, process.env.CAISHEN_PROJECT_SECRET);

      // 🆕 New SDK instance for each user
      const sdk = new CaishenSDK({ projectKey: process.env.CAISHEN_PROJECT_KEY });

      // 🚪 Connect user
      await sdk.connectAsUser({
        provider: 'custom',
        token,
      });

      // 👛 Create Ethereum wallet
      const wallet = await sdk.crypto.getWallet({
        chainType: 'ETHEREUM',
        chainId: 1,
        account: 0,
      });

      console.log(`✅ Wallet for ${userId}:`);
      console.log(`   Address: ${wallet.address}`);
      console.log(`   Public Key: ${wallet.publicKey}\n`);

    } catch (err) {
      console.error(`❌ Failed for ${userId}: ${err.message}\n`);
    }
  }
})();

```

</details>

<details>

<summary>Example 5: Creating Wallets on EVM, Bitcoin, Solana, SUI &#x26; XRP for 10 Users</summary>

```
const { CaishenSDK } = require('@caishen/sdk');
const jwt = require('jsonwebtoken');
require('dotenv').config();

// 🔁 10 users
const users = Array.from({ length: 10 }, (_, i) => `user-${i + 1}`);

// 🌐 Chain setup
const chains = [
  { name: 'Ethereum', chainType: 'ETHEREUM', chainId: 1 },
  { name: 'Solana', chainType: 'SOLANA', chainId: 101 },
  { name: 'Bitcoin', chainType: 'BITCOIN', chainId: 0 },
  { name: 'Sui', chainType: 'SUI', chainId: 1 },
  { name: 'XRP', chainType: 'XRP', chainId: 1 },
];

(async () => {
  for (const userId of users) {
    try {
      const token = jwt.sign({ id: userId }, process.env.CAISHEN_PROJECT_SECRET);
      const sdk = new CaishenSDK({ projectKey: process.env.CAISHEN_PROJECT_KEY });

      await sdk.connectAsUser({
        provider: 'custom',
        token,
      });

      console.log(`\n🧑 Creating wallets for ${userId}`);

      for (const chain of chains) {
        try {
          const wallet = await sdk.crypto.getWallet({
            chainType: chain.chainType,
            chainId: chain.chainId,
            account: 0,
          });

          console.log(`✅ ${chain.name} Wallet`);
          console.log(`   Address: ${wallet.address}`);
          console.log(`   Public Key: ${wallet.publicKey}\n`);
        } catch (err) {
          console.error(`❌ Failed to create ${chain.name} wallet for ${userId}: ${err.message}`);
        }
      }

    } catch (err) {
      console.error(`❌ Failed to connect ${userId}: ${err.message}`);
    }
  }
})();

```

</details>

#### Minimal WalletInput

```
interface MinimalWalletInput {
  account: number;
  chainType: string;
  address: string;
}
```

Used for all `cash` and `swap` functions to avoid sending sensitive data.

***

### 💸 Token Operations

> 🚫 Use `MinimalWalletInput` when possible to reduce sensitive data exposure.

#### ➕ Send Token

```
const txHash = await sdk.crypto.send({
  wallet,
  payload: {
    token: '0xTokenAddress...', // omit for native
    amount: '0.5',
    toAddress: '0xRecipient...',
  },
});
```

#### 📊 Get Balance

```
const native = await sdk.crypto.getBalance({ wallet, payload: {} });
const dai = await sdk.crypto.getBalance({
  wallet,
  payload: { token: '0x6B1754...' },
});
```

***

### 🔁 Token Swap

> 🚫 Do not send the full wallet object. Use only `{ account, chainType }`.

#### 🔍 Get Swap Route

```
const route = await sdk.crypto.getSwapRoute({
  wallet: { account: 0 },
  payload: {
    amount: '1000000000000000000',
    from: { tokenAddress: '0x...', chainType: 'ETHEREUM' },
    to: { tokenAddress: '0x...', chainType: 'ETHEREUM' },
  },
});
```

#### 🔄 Execute Swap

```
const result = await sdk.crypto.swap({
  wallet: { account: 0, chainType: 'ETHEREUM' },
  payload: { confirmationCode: 'abc123' },
});
```

<br>


---

# Agent Instructions: 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.caishen.tech/creating-wallets.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.
