Docs

Migration from SDK v4

High-level changes

  • All imports from @thirdweb-dev/* should be replaced with thirdweb SDK with sub-exports.
  • The new SDK is function based rather than class based for better tree shaking and performance.
  • All contract calls are now prepared using prepareContractCall and sent using the sendTransaction function.
  • Transactions are submitted without waiting for receipt by default. You can call the waitForReceipt function to wait for the transaction to be mined.

Progressive migration

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.

You can easily share the same wallet between the two SDKs by using the ethers5adapter utility, allowing you to progressively replace calls one by one.

import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { prepareContractCall, sendTransaction } from "thirdweb";
import { ethers5Adapter } from "thirdweb/adapters/ethers5";
const sdk = ThirdwebSDK.fromPrivateKey(pkey, chain);
// convert the signer to be used with the new thirdweb SDK
const account = await ethers5Adapter.signer.fromEthers(sdk.getSigner());
// then use the new thirdweb SDK normally
const transaction = prepareContractCall({ ... });
await sendTransaction({
transaction,
account,
});

In React, you can mix and match the v4 and v5 ThirdwebProvider, that gives you access to the hooks and functionality of both SDKs.

import { ThirdwebProvider} from "@thirdweb-dev/react" }
import { ThirdwebProvider as ThirdwebProviderV5 } from "thirdweb/react"
<ThirdwebProvider activeChain={...} clientId={...}>
<ThirdwebProviderV5>
...
</ThirdwebProviderV5>
</V4TWProvider>

From thre, you can obtain the current signer using the useSigner hook, and convert it when needed using the ethers5Adapter:

import { useSigner } from "@thirdweb-dev/react";
import { ethers5Adapter } from "thirdweb/adapters/ethers5";
const signer = useSigner();
const onClick = async () => {
// convert the signer to used with the new SDK
const account = await ethers5Adapter.signer.fromEthers(signer);
// then use the new SDK normally
const transaction = prepareContractCall({ ... });
await sendTransaction({
transaction,
account,
});
};

TypeScript Cheatsheet

Task@thirdweb-dev/sdkthirdweb
Chainsimport { Sepolia } from "@thirdweb-dev/chains"import { sepolia } from "thirdweb/chains"
Walletsimport { MetaMaskWallet } from "@thirdweb-dev/wallets"import { createWallet } from "thirdweb/wallets"
Initializenew ThirdwebSDK(...)createThirdwebClient({ ... })
Contractawait sdk.getContract(...)getContract(...) // no await
Readawait contract.call(...)await readContract(...)
Prepareawait contract.prepare(...)prepareContractCall(...) // no await
Sendawait contract.call(...)await sendTransaction(...)
Extensionsawait contract.erc721.getAll()await getNFTs(...)
Deploysdk.deployer.deployBuiltInContract(...)await deployPublishedContract(...)

React Cheatsheet

Task@thirdweb-dev/reactthirdweb
Providerimport { ThirdwebProvider} from @thirdweb-dev/reactimport { ThirdwebProvider } from "thirdweb/react"
ContractuseContract(...)getContract(...) // not a hook
AddressuseAddress(...)useActiveAccount(...) // account?.address
ReaduseContractRead(...)useReadContract(...)
WriteuseContractWrite(...)useSendTransaction()
ExtensionsuseNFTs(...)useReadContract(getNFTs, { ... })
Get SigneruseSigner()useActiveAccount()
Get WalletuseWallet()useActiveWallet()
ButtonWeb3ButtonTransactionButton
ConnectConnectWalletConnectButton
Connection StatususeConnectionStatus()useActiveWalletConnectionStatus()
Switch ChainuseSwitchChain()useSwitchActiveWalletChain()
Get Connected ChainuseChain()useSwitchActiveWalletChain()