Recommended: JavaScript SDK with React Hooks
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.This guide is currently React only.
Prerequisites
- Dynamic env ID
- Alchemy API key
- Alchemy RPC URL configured in your Dynamic Dashboard for the target network
Step By Step
1. Install dependencies
2. Configure your Alchemy environment
3. Add Dynamic to your application
In order to use Dynamic, you should wrap your app with DynamicContextProvider at the highest possible level i.e.4. Create the Alchemy Light Account hook
Create a reusable hook that:- Validates the wallet is Ethereum compatible
- Uses the Alchemy RPC URL configured in your Dynamic Dashboard for the selected chain
- Defines the chain with
defineAlchemyChainusing the resolved RPC URL - Builds a Dynamic-based Smart Account signer
- Initializes
createLightAccountAlchemyClient
useAlchemyLightAccount.ts
5. Use the hook in your app
Use the hook anywhere inside theDynamicContextProvider to get a ready Light Account client:
Home.tsx
Troubleshooting
- Missing API key: Ensure
VITE_ALCHEMY_API_KEYis set in your env. - Non-Ethereum wallet: Switch to an Ethereum wallet in Dynamic.
- RPC provider mismatch: Ensure the RPC URL configured in your Dynamic Dashboard for the selected chain is an Alchemy RPC URL.