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

# Wallet RPC Methods

> EIP-3326 and EIP-747 wallet interaction methods for chain switching and asset tracking

Voltaire implements standard wallet RPC methods defined in [EIP-3326](https://eips.ethereum.org/EIPS/eip-3326) (wallet\_switchEthereumChain, wallet\_addEthereumChain) and [EIP-747](https://eips.ethereum.org/EIPS/eip-747) (wallet\_watchAsset) for seamless wallet integration.

## Chain Management

### wallet\_switchEthereumChain

Request wallet to switch to a different Ethereum chain.

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

// Switch to Ethereum mainnet
const req = Rpc.Wallet.SwitchEthereumChainRequest('0x1');

// Switch to Polygon
const polygonReq = Rpc.Wallet.SwitchEthereumChainRequest('0x89');

// Switch to Arbitrum
const arbitrumReq = Rpc.Wallet.SwitchEthereumChainRequest('0xa4b1');
```

**Parameters:**

* `chainId` (string): Hex-encoded chain ID (e.g., "0x1" for mainnet)

**Returns:** `null` on success

**Errors:**

* `4001`: User rejected the request
* `4902`: Unrecognized chain ID (chain not added to wallet)

### wallet\_addEthereumChain

Request wallet to add a new Ethereum chain.

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

// Add Polygon network
const req = Rpc.Wallet.AddEthereumChainRequest({
  chainId: '0x89',
  chainName: 'Polygon Mainnet',
  nativeCurrency: {
    name: 'MATIC',
    symbol: 'MATIC',
    decimals: 18
  },
  rpcUrls: ['https://polygon-rpc.com'],
  blockExplorerUrls: ['https://polygonscan.com'],
  iconUrls: ['https://example.com/polygon.png']
});

// Add custom chain
const customReq = Rpc.Wallet.AddEthereumChainRequest({
  chainId: '0x539', // 1337
  chainName: 'Local Development',
  nativeCurrency: {
    name: 'Ether',
    symbol: 'ETH',
    decimals: 18
  },
  rpcUrls: ['http://localhost:8545']
});
```

**Parameters:**

* `chainId` (string): Hex-encoded chain ID
* `chainName` (string): Human-readable chain name
* `nativeCurrency` (object): Native currency info
  * `name` (string): Currency name
  * `symbol` (string): Currency symbol
  * `decimals` (number): Currency decimals (typically 18)
* `rpcUrls` (string\[]): RPC endpoint URLs
* `blockExplorerUrls` (string\[], optional): Block explorer URLs
* `iconUrls` (string\[], optional): Chain icon URLs

**Returns:** `null` on success

**Errors:**

* `4001`: User rejected the request
* `4902`: Chain already exists

## Asset Management

### wallet\_watchAsset

Request wallet to track a token (typically ERC-20).

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

// Add DAI token
const req = Rpc.Wallet.WatchAssetRequest({
  type: 'ERC20',
  options: {
    address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
    symbol: 'DAI',
    decimals: 18,
    image: 'https://assets.example.com/dai.png'
  }
});

// Add USDC token
const usdcReq = Rpc.Wallet.WatchAssetRequest({
  type: 'ERC20',
  options: {
    address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
    symbol: 'USDC',
    decimals: 6
  }
});
```

**Parameters:**

* `type` (string): Asset type (typically "ERC20")
* `options` (object): Asset details
  * `address` (string): Token contract address
  * `symbol` (string): Token symbol
  * `decimals` (number): Token decimals
  * `image` (string, optional): Token icon URL

**Returns:** `boolean` - `true` if token was added, `false` if rejected

**Errors:**

* `4001`: User rejected the request

## Permissions

### wallet\_requestPermissions

Request specific permissions from the wallet.

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

// Request eth_accounts permission
const req = Rpc.Wallet.RequestPermissionsRequest({
  eth_accounts: {}
});
```

**Parameters:**

* Object with permission names as keys (e.g., `eth_accounts`)

**Returns:** Array of granted permission objects

**Errors:**

* `4001`: User rejected the request

### wallet\_getPermissions

Get currently granted permissions.

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

const req = Rpc.Wallet.GetPermissionsRequest();
```

**Returns:** Array of permission objects

### wallet\_revokePermissions

Revoke specific permissions.

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

// Revoke eth_accounts permission
const req = Rpc.Wallet.RevokePermissionsRequest({
  eth_accounts: {}
});
```

**Parameters:**

* Object with permission names to revoke as keys

**Returns:** `null` on success

## Error Handling

Standard wallet error codes:

```typescript theme={null}
import { WalletErrorCode } from '@tevm/voltaire/jsonrpc';

WalletErrorCode.USER_REJECTED;        // 4001 - User rejected
WalletErrorCode.UNAUTHORIZED;         // 4100 - Unauthorized
WalletErrorCode.UNSUPPORTED_METHOD;   // 4200 - Unsupported method
WalletErrorCode.DISCONNECTED;         // 4900 - Disconnected
WalletErrorCode.CHAIN_DISCONNECTED;   // 4901 - Chain disconnected
WalletErrorCode.UNRECOGNIZED_CHAIN;   // 4902 - Unrecognized chain
```

Error helper functions:

```typescript theme={null}
import {
  userRejectedError,
  unauthorizedError,
  unsupportedMethodError,
  unrecognizedChainError
} from '@tevm/voltaire/jsonrpc';

// Create standard errors
const err1 = userRejectedError();
const err2 = unsupportedMethodError('wallet_foo');
const err3 = unrecognizedChainError('0x999');
```

## Usage with Providers

```typescript theme={null}
import { Rpc } from '@tevm/voltaire/jsonrpc';

async function switchChain(provider: any, chainId: string) {
  try {
    const req = Rpc.Wallet.SwitchEthereumChainRequest(chainId);
    await provider.request(req);
  } catch (error: any) {
    if (error.code === 4902) {
      // Chain not added, try adding it
      const addReq = Rpc.Wallet.AddEthereumChainRequest({
        chainId,
        chainName: 'Custom Chain',
        nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
        rpcUrls: ['https://rpc.example.com']
      });
      await provider.request(addReq);
    } else if (error.code === 4001) {
      console.log('User rejected chain switch');
    }
  }
}

async function addToken(provider: any, address: string) {
  const req = Rpc.Wallet.WatchAssetRequest({
    type: 'ERC20',
    options: {
      address,
      symbol: 'TOKEN',
      decimals: 18
    }
  });

  const added = await provider.request(req);
  console.log(added ? 'Token added' : 'Token rejected');
}
```

## References

* [EIP-3326: Wallet Switch Ethereum Chain RPC Method](https://eips.ethereum.org/EIPS/eip-3326)
* [EIP-747: wallet\_watchAsset RPC Method](https://eips.ethereum.org/EIPS/eip-747)
* [EIP-2255: Wallet Permissions System](https://eips.ethereum.org/EIPS/eip-2255)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.