|
| 1 | +import { |
| 2 | + ArticleCard, |
| 3 | + GithubTemplateCard, |
| 4 | + Grid, |
| 5 | + ExpandableGrid, |
| 6 | + createMetadata, |
| 7 | + OpenSourceCard, |
| 8 | + Stack, |
| 9 | + Steps, |
| 10 | + Step, |
| 11 | + InstallTabs, |
| 12 | + Callout |
| 13 | +} from "@doc"; |
| 14 | + |
| 15 | +[Migrate from React v4](/react/v5/migrate) |
| 16 | + |
| 17 | +# Installation & Setups |
| 18 | + |
| 19 | +Welcome to the migration guide for updating your React SDK from version 4 to version 5. This guide will walk you through the necessary steps to ensure a smooth transition. In this section, we'll cover the installation process for the new version of the SDK. |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +#### Below is how you install thirdweb v4 SDKs |
| 24 | +<InstallTabs |
| 25 | + npm="npm i @thirdweb-dev/sdk @thirdweb-dev/react [email protected]" |
| 26 | + yarn="yarn add @thirdweb-dev/sdk @thirdweb-dev/react [email protected]" |
| 27 | + pnpm="pnpm i @thirdweb-dev/sdk @thirdweb-dev/react [email protected]" |
| 28 | + bun="bun i @thirdweb-dev/sdk @thirdweb-dev/react [email protected]" |
| 29 | +/> |
| 30 | + |
| 31 | +#### With the latest version, everything comes in one single package |
| 32 | +<InstallTabs |
| 33 | + npm="npm i thirdweb" |
| 34 | + yarn="yarn add thirdweb" |
| 35 | + pnpm="pnpm i thirdweb" |
| 36 | + bun="bun i thirdweb" |
| 37 | +/> |
| 38 | + |
| 39 | + |
| 40 | +## Setups |
| 41 | + |
| 42 | +Once you have installed the latest package (alongside the older version that you want to replace), you can start the migration process. |
| 43 | + |
| 44 | +### ThirdwebProvider |
| 45 | + |
| 46 | +In the latest SDK, the [`ThirdwebProvider`](/references/typescript/v5/ThirdwebProvider) no longer accepts any prop such as `activeChain`, `clientId` or any extra SDK options. |
| 47 | +Instead, you only need to pass the clientId when necessary (we'll talk more about this in a few sections below). |
| 48 | + |
| 49 | +```tsx |
| 50 | +import { ThirdwebProvider } from "thirdweb/react"; |
| 51 | + |
| 52 | +<ThirdwebProvider> |
| 53 | + ... |
| 54 | +</ThirdwebProvider> |
| 55 | +``` |
| 56 | + |
| 57 | +###### Progressive migration |
| 58 | + |
| 59 | + |
| 60 | +If you're currently using the `@thirdweb-dev/sdk`, you can progressively migrate to the new `thirdweb` SDK. Both SDKs can be used side by side and are interoperable with each other. |
| 61 | + |
| 62 | +In React, you can mix and match the v4 and v5 `ThirdwebProvider`, that gives you access to the hooks and functionality of both SDKs. |
| 63 | +This way, once you have moved away from all the v4 functionalities, you can finally remove the `ThirdwebProviderV4` from your app. |
| 64 | + |
| 65 | +```tsx |
| 66 | +import { ThirdwebProvider as ThirdwebProviderV4 } from "@thirdweb-dev/react"; |
| 67 | +import { ThirdwebProvider } from "thirdweb/react"; // v5 |
| 68 | + |
| 69 | +<ThirdwebProviderV4 activeChain={...} clientId={...}> |
| 70 | + <ThirdwebProvider> |
| 71 | + ... |
| 72 | + </ThirdwebProvider> |
| 73 | +</ThirdwebProviderV4> |
| 74 | +``` |
| 75 | + |
| 76 | +### Connecting wallets |
| 77 | + |
| 78 | +Similar to v4's `ConnectWallet` component, the latest version has the [`ConnectButton`](/connect/sign-in/ConnectButton) component which has the same functionality. |
| 79 | + |
| 80 | +However, unlike with v4 where the number of supported wallets is limited (about 20), and adding more wallets mean your app becomes heavier, |
| 81 | +the SDK v5 supports [over 300 wallets](/typescript/v5/supported-wallets) with virtually no impact to your application. |
| 82 | + |
| 83 | +Here's how you use the new `ConnectButton`: |
| 84 | + |
| 85 | +```tsx |
| 86 | +import { createThirdwebClient } from "thirdweb"; |
| 87 | +import { ConnectButton } from "thirdweb/react"; |
| 88 | + |
| 89 | +const client = createThirdwebClient({ |
| 90 | + clientId: process.env.NEXT_PUBLIC_TW_CLIENT_ID, |
| 91 | +}); |
| 92 | + |
| 93 | +<ConnectButton client={client} /> |
| 94 | +``` |
| 95 | + |
| 96 | +Notice how you are passing the thirdweb client to the component itself and not to the `ThirdwebProvider` like in v4? |
| 97 | +By not putting every config inside the context wrapper, we were able to make the SDK v5 much more lightweight since you only load what you need! |
| 98 | + |
| 99 | + |
| 100 | +Tip: You can reuse the thirdweb client object by putting it in a file and export it. |
| 101 | +```ts |
| 102 | +// @lib/client.ts |
| 103 | + |
| 104 | +import { createThirdwebClient } from "thirdweb"; |
| 105 | + |
| 106 | +export const client = createThirdwebClient({ |
| 107 | + clientId: process.env.NEXT_PUBLIC_TW_CLIENT_ID, |
| 108 | +}); |
| 109 | + |
| 110 | +``` |
0 commit comments