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) to get started.
Before calling EVM-specific methods like getWalletClient(), you must narrow the wallet type with the isEthereumWallet guard. Without it, TypeScript won’t expose EVM methods and the call will throw at runtime with no hint about what went wrong.
import { isEthereumWallet } from '@dynamic-labs/ethereum';if (!isEthereumWallet(wallet)) { throw new Error('This wallet is not an Ethereum wallet');}// wallet is now typed as EthereumWallet — EVM methods are availableconst walletClient = await wallet.getWalletClient();
isEthereumWallet is exported from @dynamic-labs/ethereum. It checks wallet.chain === 'EVM' and narrows the type to EthereumWallet, which exposes getWalletClient(), getPublicClient(), and other EVM-specific methods.
If you want to read data from the blockchain, you will want a “Public Client” (Viem terminology)
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'; const { primaryWallet } = useDynamicContext(); const getEnsName = async () => { const publicClient = await primaryWallet?.getPublicClient() // Now you can use the public client to read data from the blockchain const ens = await publicClient?.getEnsName({ address: primaryWallet.address }) return ens }
If you want to write data to the blockchain, you will need a “Wallet Client” (Viem terminology), or a “Signer” (Ethers terminology). Both allow you to sign transactions with the private key.
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'; import { isEthereumWallet } from '@dynamic-labs/ethereum'; const { primaryWallet } = useDynamicContext(); const sendTransaction = async () => { if(!primaryWallet || !isEthereumWallet(primaryWallet)) { return; } const walletClient = await primaryWallet.getWalletClient(); // Now you can use the wallet client to write data to the blockchain const tx = await walletClient?.sendTransaction({ to: '0x1234567890abcdef', value: '1000000000000000000' }); return tx }