Providers
Alchemy
This guide shows you how to use Dynamic as a signer for Alchemy Smart Accounts.
Was this page helpful?
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
π Stablecoin Accounts are live! Learn more
npm i -s @dynamic-labs/sdk-react-core @dynamic-labs/ethereum
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core'
import { EthereumWalletConnectors } from '@dynamic-labs/ethereum'
import Home from './Home'
// Found in your Dynamic dashboard (https://app.dynamic.xyz/dashboard/developer/api)
const DYNAMIC_ENVIRONMENT_ID = 'XXXXX'
const App = () => {
return (
<div className="app">
<DynamicContextProvider
settings={{
environmentId: DYNAMIC_ENVIRONMENT_ID,
walletConnectors: [EthereumWalletConnectors],
}}
>
<Home />
</DynamicContextProvider>
</div>
)
}
export default App
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-hooks
const { 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 ISmartContractAccount
export const dynamicSigner: SmartAccountSigner = new WalletClientSigner(
dynamicProvider,
'dynamic' // signer type
)
import { AlchemyProvider } from '@alchemy/aa-alchemy'
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from '@alchemy/aa-accounts'
import { sepolia } from 'viem/chains'
import { dynamicSigner } from './dynamic'
const chain = sepolia
const provider = new AlchemyProvider({
apiKey: 'ALCHEMY_API_KEY',
chain,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
chain,
owner: dynamicSigner,
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
)
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-hooks
const { 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 ISmartContractAccount
export const dynamicSigner: SmartAccountSigner = new WalletClientSigner(
dynamicProvider,
'dynamic' // signer type
)
Was this page helpful?