This recipe uses the Dynamic JavaScript SDK (
@dynamic-labs-sdk/client + @dynamic-labs-sdk/solana). The React tab also uses @dynamic-labs-sdk/react-hooks. See the Quickstart for the base setup.Prerequisites
- The Dynamic JS SDK initialized, with the Solana extension registered via
addSolanaExtension(); see Adding Solana Extensions - Installed dependencies:
@coral-xyz/anchor@solana/web3.js@dynamic-labs-sdk/client@dynamic-labs-sdk/solana- For the React tab:
@dynamic-labs-sdk/react-hooksand@tanstack/react-query(DynamicProvidermounted at the root; see the React Quickstart)
- Your Anchor program’s IDL and TypeScript types
Step 1: Build the Anchor provider
Adapt the SDK’s transaction-signing helpers to theWallet interface Anchor expects.
- JavaScript
- React
Create a file (e.g.,
anchor-provider.ts) and add the following code:Step 2: Wrap your app with the provider
If you’re using the JavaScript tab from Step 1, skip this step and callcreateAnchorProvider() directly wherever you need the program.
For the React context, mount AnchorProviderComponent inside DynamicProvider so it can read the connected wallet from the JS SDK’s hooks. QueryClientProvider must wrap DynamicProvider: every hook in @dynamic-labs-sdk/react-hooks is built on TanStack Query.
Step 3: Call a program method
Here’s an example of calling a program method and sending a transaction using the connected Dynamic wallet.- JavaScript
- React