> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# 管理钱包

> 使用这些代码片段示例，通过 Tenderly SDK 添加、更新、移除和获取钱包。

[Tenderly SDK](/platform/sdk/introduction) 提供了 **`WalletRepository`** 类，用于管理与您的项目相关联的钱包。**`WalletRepository`** 允许您添加、更新和移除钱包。

初始化 Tenderly SDK 后，您可以使用 **`wallets`** 命名空间访问 **`WalletRepository`** 实例。有关等效的合约操作，请参见 [管理合约](/platform/sdk/managing-contracts)。

### 添加钱包

要添加新钱包，请使用 **`wallets`** 命名空间的 **`add`** 方法：

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
try {
  const walletAddress = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
  const addedWallet = await tenderly.wallets.add(walletAddress, {
    displayName: 'My Wallet',
  });
  console.log('Added wallet:', addedWallet);
} catch (error) {
  console.error('Error adding wallet:', error);
}
```

### 更新钱包

要更新现有钱包，请使用 **`wallets`** 命名空间的 **`update`** 方法：

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
try {
  const walletAddress = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
  const updatedWallet = await tenderly.wallets.update(walletAddress, {
    displayName: 'My Wallet',
  });
  console.log('Updated wallet:', updatedWallet);
} catch (error) {
  console.error('Error updating wallet:', error);
}
```

### 移除钱包

要移除钱包，请使用 **`wallets`** 命名空间的 **`remove`** 方法：

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
try {
  const walletAddress = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
  await tenderly.wallets.remove(walletAddress);
  console.log('Wallet removed successfully');
} catch (error) {
  console.error('Error removing wallet:', error);
}
```

### 获取钱包列表

要获取与您项目相关联的钱包，请使用 **`wallets`** 命名空间的 **`getAll`** 方法：

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
try {
  const allWallets = await tenderly.wallets.getAll();
  console.log('All wallets:', allWallets);
} catch (error) {
  console.error('Error fetching wallets:', error);
}
```

### 获取单个钱包

要通过 ID 获取单个钱包，请使用 **`wallets`** 命名空间的 **`get`** 方法：

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
try {
  const walletAddress = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
  const wallet = await tenderly.wallets.get(walletAddress);
  console.log('Fetched wallet:', wallet);
} catch (error) {
  console.error('Error fetching wallet:', error);
}
```
