# Get a wallet

The active wallet is the wallet currently being used in your application.

You can view the active wallet using the `wallets` property from either the [`useEmbeddedEthereumWallet`](/docs/products/embedded-wallet/react-native/hooks/useEmbeddedEthereumWallet) or [`useEmbeddedSolanaWallet`](/docs/products/embedded-wallet/react-native/hooks/useEmbeddedSolanaWallet) hook, depending on your target blockchain.

## Using Openfort wallets

The first thing that any app would want to do is list the wallets linked to the user and show the active wallet.

### List user wallets

:::code-group

```tsx [Ethereum]
import { useEmbeddedEthereumWallet } from "@openfort/react-native"
import { View, Text } from "react-native"

function SampleComponent() {
  const { wallets } = useEmbeddedEthereumWallet()
  const activeWallet = wallets?.[0];

  return (
    <View>
      {wallets.map((wallet) => (
        <Text key={wallet.address}>{wallet.address}</Text>
      ))}
    </View>
  )
}
```

```tsx [Solana]
import { useEmbeddedSolanaWallet } from "@openfort/react-native"
import { View, Text } from "react-native"

function SampleComponent() {
  const { wallets } = useEmbeddedSolanaWallet()
  const activeWallet = wallets?.[0];

  return (
    <View>
      {wallets.map((wallet) => (
        <Text key={wallet.address}>{wallet.address}</Text>
      ))}
    </View>
  )
}
```

:::

This returns a list of `ConnectedEmbeddedEthereumWallet` or `ConnectedEmbeddedSolanaWallet` objects, depending on which hook you use.

### Change active wallet

To change the active wallet, use the `setActive` method from the appropriate hook.
In this example, we change the active wallet by providing the address.

:::code-group

```tsx [Ethereum]
import { useEmbeddedEthereumWallet } from "@openfort/react-native"
import { ActivityIndicator } from "react-native"
import { Hex } from "viem";

function SampleComponent() {
  const { status, setActive } = useEmbeddedEthereumWallet()

  const handleChangeWallet = async (address: Hex) => {
    await setActive({ address });
    console.log("Active wallet changed to:", address);
  };

  if (status === 'connecting') {
    return <ActivityIndicator />
  }

  // ...
}
```

```tsx [Solana]
import { useEmbeddedSolanaWallet } from "@openfort/react-native"
import { ActivityIndicator } from "react-native"

function SampleComponent() {
  const { status, setActive } = useEmbeddedSolanaWallet()

  const handleChangeWallet = async (address: string) => {
    await setActive({ address });
    console.log("Active wallet changed to:", address);
  };

  if (status === 'connecting') {
    return <ActivityIndicator />
  }

  // ...
}
```

:::

When `setActive` completes successfully, the hook's status transitions to `connected` and the `activeWallet` property updates.

## User wallet

The embedded wallet object represents the wallet associated with a user. Openfort supports two wallet types:

* **ConnectedEmbeddedEthereumWallet** - For Ethereum chains (smart accounts)
* **ConnectedEmbeddedSolanaWallet** - For Solana (EOA wallets)

### Ethereum wallet

The **ConnectedEmbeddedEthereumWallet** object represents an Ethereum embedded wallet. It provides:

* Wallet address and optional owner address
* Implementation type (for example, Upgradeable contract versions)
* Chain type for the wallet (Ethereum)
* Wallet index for multiple wallet support
* A method to obtain the EIP-1193 provider for direct interactions

**Properties:**

| Property | Type | Description |
|----------|------|-------------|
| `id` | `string` | Unique identifier for the wallet |
| `address` | `string` | The wallet address (hex string) |
| `chainType` | `ChainTypeEnum.EVM` | The chain type for the wallet |
| `chainId?` | `number` | The chain ID for the wallet |
| `ownerAddress?` | `string` | The owner's address associated with the wallet |
| `factoryAddress?` | `string` | The factory contract address used to deploy the wallet |
| `salt?` | `string` | The salt used for deterministic wallet deployment |
| `accountType` | `AccountTypeEnum` | The account type (SMART\_ACCOUNT or EOA) |
| `implementationAddress?` | `string` | The implementation contract address |
| `createdAt?` | `number` | Timestamp when the wallet was created |
| `implementationType?` | `string` | The implementation type of the wallet (for example, `Upgradeable_v05`) |
| `recoveryMethod?` | `RecoveryMethod` | The recovery method used for this wallet |
| `recoveryMethodDetails?` | `RecoveryMethodDetails` | Details about the recovery method configuration |
| `walletIndex` | `number` | Index of the wallet for users with multiple wallets |
| `getProvider` | `() => Promise<OpenfortEmbeddedEthereumWalletProvider>` | Function to get the EIP-1193 provider |

### Solana wallet

The **ConnectedEmbeddedSolanaWallet** object represents a Solana embedded wallet. It provides:

* Wallet address (base58 encoded)
* Chain type for the wallet (Solana)
* Wallet index for multiple wallet support
* A method to obtain the Solana provider for signing transactions

**Properties:**

| Property | Type | Description |
|----------|------|-------------|
| `id` | `string` | Unique identifier for the wallet |
| `address` | `string` | The wallet address (base58 string) |
| `chainType` | `'SVM'` | The chain type for the wallet |
| `createdAt?` | `number` | Timestamp when the wallet was created |
| `recoveryMethod?` | `RecoveryMethod` | The recovery method used for this wallet |
| `recoveryMethodDetails?` | `RecoveryMethodDetails` | Details about the recovery method configuration |
| `walletIndex` | `number` | Index of the wallet for users with multiple wallets |
| `getProvider` | `() => Promise<OpenfortEmbeddedSolanaWalletProvider>` | Function to get the Solana provider |

### Example usage

The embedded wallet hooks provide access to the user wallet object through a discriminated union state:

:::code-group

```tsx [Ethereum]
import React from "react";
import { View, Text } from "react-native";
import { useEmbeddedEthereumWallet } from "@openfort/react-native";

const MyComponent = () => {
  const ethereum = useEmbeddedEthereumWallet();

  return (
    <View>
      <Text style={{ fontSize: 20 }}>User Wallet</Text>
      {ethereum.status === 'connected' && (
        <Text>Active: {ethereum.activeWallet.address}</Text>
      )}
      <Text style={{ fontSize: 16, marginTop: 10 }}>All Wallets</Text>
      {ethereum.wallets.map((wallet) => (
        <Text key={wallet.address}>
          {wallet.address.slice(0, 10)}... (index: {wallet.walletIndex})
        </Text>
      ))}
    </View>
  );
};
```

```tsx [Solana]
import React from "react";
import { View, Text } from "react-native";
import { useEmbeddedSolanaWallet } from "@openfort/react-native";

const MyComponent = () => {
  const solana = useEmbeddedSolanaWallet();

  return (
    <View>
      <Text style={{ fontSize: 20 }}>User Wallet</Text>
      {solana.status === 'connected' && (
        <Text>Active: {solana.activeWallet.address}</Text>
      )}
      <Text style={{ fontSize: 16, marginTop: 10 }}>All Wallets</Text>
      {solana.wallets.map((wallet) => (
        <Text key={wallet.address}>
          {wallet.address.slice(0, 10)}... (index: {wallet.walletIndex})
        </Text>
      ))}
    </View>
  );
};
```

:::
