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

# Upgrade SDK from V2 to V3

<Card title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](/javascript/reference/react-quickstart) to get started.
</Card>

<Note>
  If you are looking for the upgrade guide for V3 Wallets, please see [here](/react/wallets/embedded-wallets/mpc/upgrade-guide). This guide is for the SDK only.
</Note>

## Changes in 3.0.0-alpha.53 -> latest

See [here](/react/reference/upgrade/v3#2-x-x-to-3-0-0-alpha-52) for changes from 2.x.x to 3.0.0-alpha.52

### Wallet and WalletConnectors

#### No undesired prompting

No more undesired prompting to reconnect or switch wallets when not required!

Now a wallet can be made primary at any time without extra prompting, even if the wallet is not connected or unlocked.

Users will only be prompted to connect/unlock when sending/signing a transaction if the wallet is not connected or unlocked already.

#### Wallet object has changed

* wallet.authenticated changed to wallet.isAuthenticated
* wallet.connected is now an async method wallet.isConnected()
* wallet.network is now an async method wallet.getNetwork()
* wallet.chain valid values have changed

We used to use values like 'eip155' for wallet.chain. This is no longer the case. The new valid values for wallet.chain are the following:

```
'ALGO' | 'BTC' | 'COSMOS' | 'EVM' | 'FLOW' | 'SOL' | 'STARK'
```

The Wallet object has changed and now contains some methods that were previously on the WalletConnector object. Each chain specific wallet has its own methods. The methods specific to the main chains on the wallet object are:

* EthereumWallet

  * getPublicClient
  * getWalletClient

* SolanaWallet

  * getConnection
  * getSigner

* BitcoinWallet

  * sendBitcoin
  * sendRawTransaction
  * signMessageWithAddress
  * signPsbt
  * signPsbts

* CosmosWallet

  * getOfflineSigner
  * getProvider

* StarknetWallet

  * getProvider
  * getWalletAccount

* AlgorandWallet
  * getSigner

### Wallet type checking

You should always use our utilities to check that you're dealing with the correct wallet type before calling the wallet specific methods.

```tsx theme={"system"}
import { isEthereumWallet } from '@dynamic-labs/ethereum';
import { isSolanaWallet } from '@dynamic-labs/solana';
import { isBitcoinWallet } from '@dynamic-labs/bitcoin';

const { primaryWallet } = useDynamicContext();

if (isEthereumWallet(primaryWallet)) {
  console.log('call any ethereum wallet method')
}

if (isSolanaWallet(primaryWallet)) {
  console.log('call any solana wallet method')
}

if (isBitcoinWallet(primaryWallet)) {
  console.log('call any bitcoin wallet method')
}
```

Learn more in the wallet guides, starting with [Accessing Wallets](/react/wallets/using-wallets/accessing-wallets).

#### Wallet connector object has changed

Since we have moved some methods from the connector to the wallet object, the wallet connector object is now slimmed down. Use the chain-specific wallet guides (for example [Using EVM Wallets](/react/wallets/using-wallets/evm/using-evm-wallets)) for method examples.

As with the wallet object, each chain specific wallet connector has its own methods so we recommend checking out the appropriate section for the chain you are working with.

<Tabs>
  <Tab title="Before">
    ```jsx theme={"system"}
    import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
    const { primaryWallet } = useDynamicContext();
    const fetchBalance = async () => {
      const balance = await primaryWallet?.connector.getBalance();
    };
    ```
  </Tab>

  <Tab title="After">
    ```jsx theme={"system"}
    import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
      const { primaryWallet } = useDynamicContext();
      const fetchBalance = async () => {
        const balance = await primaryWallet?.getBalance();
      };
    ```
  </Tab>
</Tabs>

### Return value type changes

In V2, you needed to type method return values on specific wallet methods like fetching the Viem public client, Viem wallet client, Solana connection etc. In V3, you no longer need to do this.

All you have to do is check for the wallet type (as shown in the previous section), and all the methods will come typed for you.

<Tabs>
  <Tab title="Before">
    ```tsx theme={"system"}
    import { WalletClient, Transport, Chain, Account } from 'viem'

    import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
      const { primaryWallet } = useDynamicContext();
      const walletClient = await primaryWallet.connector.getWalletClient<WalletClient<Transport, Chain, Account>>();
    ```
  </Tab>

  <Tab title="After">
    ```tsx theme={"system"}
    import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
    import { isEthereumWallet } from '@dynamic-labs/ethereum'
      const { primaryWallet } = useDynamicContext();
      if (!isEthereumWallet(primaryWallet)) {
        throw new Error('This wallet is not a Ethereum wallet');
      }
      const walletClient = await primaryWallet.getWalletClient();
    ```
  </Tab>
</Tabs>

### Smart Wallet connector updates

* getEOAConnector has been removed

The `getEOAConnector` method is no longer available, you can use [the useSmartWallets hook](/react/reference/hooks/wallets/usesmartwallets) to get the EOA wallet.

<Before>
  ```tsx theme={"system"}
  import { isZeroDevConnector } from "@dynamic-labs/ethereum-aa";
  const Component = () => {
    const { primaryWallet } = useDynamicContext();
    const { connector } = primaryWallet;
    if (!isZeroDevConnector(connector)) {
      return;
      }
    const signerConnector = connector.getEOAConnector();
    if (!signerConnector) {
      return;
    }
      // Do your thing!
  };
  ```
</Before>

<After>
  ```tsx theme={"system"}
  import { useSmartWallets } from '@dynamic-labs/sdk-react-core'; 
  const Component = () => {
    const { getEOAWallet } = useSmartWallets();
    const { primaryWallet } = useDynamicContext();
    const signer = getEOAWallet(primaryWallet);
  // Do your thing!
  };
  ```
</After>

### Ethers support refactored

Instead of using the `EthersExtension` on the Context Provider, you now need to use the `ethers-v6` package directly, which exports all of the Ethers specific methods.

<Tabs>
  <Tab title="Before">
    ```jsx theme={"system"}
    // App.tsx
    import { EthersExtension } from '@dynamic-labs/ethers-v6'

    <DynamicContextProvider
      settings={{
        environmentId: 'XXXXX',
        walletConnectorExtensions: [EthersExtension],
      }}
    >
    </DynamicContextProvider>

    // Main.tsx
    import { useDynamicContext } from '@dynamic-labs/sdk-react-core'

    const { primaryWallet } = useDynamicContext()
    const signer = primaryWallet?.connector.ethers?.getSigner();
    ```
  </Tab>

  <Tab title="After">
    ```jsx theme={"system"}
    // App.tsx
     <DynamicContextProvider
      settings={{
        environmentId: 'XXXXX',
      }}
    >
    </DynamicContextProvider>

    // Main.tsx
    import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
    import { getSigner } from '@dynamic-labs/ethers-v6'

    const { primaryWallet } = useDynamicContext()
    const signer = await getSigner(primaryWallet)
    ```
  </Tab>
</Tabs>

### Helper method removed

* createWalletClientFromWallet has been removed

The createWalletClientFromWallet function is no longer available, you can use the `getWalletClient` method on the wallet object instead.

<CodeGroup>
  ```tsx Before theme={"system"}
  import { createWalletClientFromWallet } from '@dynamic-labs/sdk-react-core';
  ```

  ```tsx After theme={"system"}
  import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
  const { primaryWallet } = useDynamicContext()

  const walletClient = await primaryWallet?.getWalletClient()
  ```
</CodeGroup>

### SignWithEmailWalletName has been removed

Instead please use the available email login flows

## 2.X.X to 3.0.0-alpha.52

### Packages restructuring

#### Solana Utils

@dynamic-labs/solana-utils has been renamed to @dynamic-labs/solana-core

#### Viem Utils

@dynamic-labs/viem-utils has been renamed to @dynamic-labs/ethereum-core

#### Ethereum RPC provider

@dynamic-labs/rpc-provider-ethereum has been removed. You can now use @dynamic-labs/ethereum-core to get the RPC provider.

#### Solana RPC provider

@dynamic-labs/rpc-provider-solana has been removed. You can now use @dynamic-labs/solana-core to get the RPC provider.

#### Starknet RPC provider

@dynamic-labs/rpc-provider-starknet has been removed. You can now use @dynamic-labs/starknet-core to get the RPC provider.

### UserProfile

Removed props that should be retrieved from the primaryWallet: `chain`, `ens`, `wallet`
Remove `isAuthenticatedWithAWallet` as a prop and added it as a helper method.
See [isAuthenticatedWithAWallet](/react/reference/utilities/isauthenticatedwithawallet)

### Removed props from `useDynamicContext`

`hideEmbeddedWalletTransactionUIs` has been removed from useDynamicContext. This is now [a toggle in the dashboard](https://app.dynamic.xyz/dashboard/embedded-wallets/dynamic).

`setPrimaryWallet` has been removed. You should use [useSwitchWallet](/react/reference/hooks/wallets/useswitchwallet#useswitchwallet) instead.

`isAuthenticated` has been removed. Please refer to [this page](/react/reference/loading-login-states) for other ways to check the login state.

`walletConnector` has been removed. You can get access to it by getting the primary wallet prop and doing `primaryWallet?.connector`.

`walletConnectorOptions` has been removed. You can get access to the available wallet options from the [useWalletOptions hook](/react/reference/hooks/wallets/usewalletoptions).

### Replaced props

* `setDefaultTabIndex` replaced with `setSelectedTabIndex` in useDynamicContext

This function is used to create [wallet list views](/react/using-our-ui/design-customizations/tutorials/wallet-list-views-guide).

<CodeGroup>
  ```tsx Before theme={"system"}
  const { setDefaultTabIndex } = useDynamicContext();
  const onChangeTab = (index: number) => {
    setDefaultTabIndex(index);
  };
  ```

  ```tsx After theme={"system"}
  const { setSelectedTabIndex } = useDynamicContext();
  const onChangeTab = (index: number) => {
    setSelectedTabIndex(index);
  };
  ```
</CodeGroup>

### Package restructuring

* ethers-v5 no longer available

We no longer support ethers v5. If you are using ethers v5 and wish to keep using ethers with Dynamic,
please upgrade to ethers v6 by following [this guide](https://docs.ethers.org/v6/migrating/), and then switch
to using our `ethers-v6` package. They have the same usability.

* rpcProviders no longer available in the sdk-react-core packages

The type DynamicRPCProviders that used to be exported from @dynamic-labs/sdk-react-core is no longer available and has been replaced with individual packages i.e. `@dynamic-labs/ethereum-core` & `@dynamic-labs/solana-core`:

<CodeGroup>
  ```tsx Before theme={"system"}
  import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
  const App = () => {
    const { rpcProviders } = useDynamicContext();
    console.log(rpcProviders.evmProviders);
    console.log(rpcProviders.solanaProviders);
  };
  ```

  ```tsx After theme={"system"}
  import { useRpcProviders } from '@dynamic-labs/sdk-react-core';
  import { evmProvidersSelector } from '@dynamic-labs/ethereum-core';
  import { solanaProvidersSelector } from '@dynamic-labs/solana-core';

  const App = () => {
    const { providers: evmProviders } = useRpcProviders(evmProvidersSelector);
    const { providers: solanaProviders } = useRpcProviders(solanaProvidersSelector);

    console.log(evmProviders);
    console.log(solanaProviders);
  }
  ```
</CodeGroup>

### Events arguments

* [onAuthSuccess](/react/reference/events/onauthsuccess) doesn't return an authToken anymore

* onEmbeddedWalletCreated returns the user instead of the authToken

You can call [getAuthToken](/react/reference/utilities/getauthtoken) to access the authToken at any time!

### Other

* Polyfill for Solana Embedded Wallet users

You may need to polyfill the 'crypto' module.

webpack.config.js:

```typescript theme={"system"}
config.resolve.fallback = {
  ...config.resolve.fallback,
  crypto: require.resolve('crypto-browserify'),
}
```

vite.config.ts

```typescript theme={"system"}
import { nodePolyfills } from 'vite-plugin-node-polyfills';

plugins: [
      nodePolyfills({
        globals: {
          global: true,
        },
        include: [],
      }),
    ],
```

### Renamed Hooks

`useSelectWalletOption` has been renamed to `useWalletOptions`

### New Hooks

* Re-initialize the SDK (useReinitialize)

```tsx theme={"system"}
import {
  DynamicContextProvider,
  useReinitialize,
} from '@dynamic-labs/sdk-react-core';

const ReInitButton = () => {
  const reinitialize = useReinitialize();

  return (
    <button onClick={reinitialize}>Reinitialize</button>
  );
}

const App = () => {
  return (
    <DynamicContextProvider>
      <ReInitButton />
    </DynamicContextProvider>
  )
}
```

* Trigger state refresh (useRefreshUser)

```tsx theme={"system"}
import {
  DynamicContextProvider,
  useRefreshUser,
} from '@dynamic-labs/sdk-react-core';

const RefreshButton = () => {
  const refresh = useRefreshUser();

  return (
    <button onClick={refresh}>Reinitialize</button>
  );
}

const App = () => {
  return (
    <DynamicContextProvider>
      <RefreshButton />
    </DynamicContextProvider>
  )
}
```

```
```

```
```

```
```
