By default, the latest version of the Dynamic SDK ships with Viem. If you need to use Ethers, please refer to this guide.
In this example, we are installing only the Ethereum connectors in order to
keep bundle size light. If you need any others, you can find the references
here.
Copy
Ask AI
npm i -s @dynamic-labs/sdk-react-core @dynamic-labs/ethereum
Next, inside any component which is wrapped by the above DynamicContextProvider, use the useDynamicContext hook to fetch your provider, and create a SmartAccountSigner:
Copy
Ask AI
import { WalletClientSigner, type SmartAccountSigner } from '@alchemy/aa-core'import { useDynamicContext } from '@dynamic-labs/sdk-react-core'import { isEthereumWallet } from '@dynamic-labs/ethereum'// eslint-disable-next-line react-hooks/rules-of-hooksconst { primaryWallet } = useDynamicContext()if (!isEthereumWallet(primaryWallet)) { throw new Error('This wallet is not a Ethereum wallet');}const dynamicProvider = await primaryWallet?.getWalletClient()// a smart account signer you can use as an owner on ISmartContractAccountexport const dynamicSigner: SmartAccountSigner = new WalletClientSigner( dynamicProvider, 'dynamic' // signer type)