The createWalletClientFromWallet utility function will take any Wallet from the Dynamic context and return a Viem WalletClient with the Account and Chain set.

This is useful if you want to interact with a particular wallet via viem or for other 3rd party packages that require a WalletClient from viem.


Signing message via viem with the primary wallet

import { useDynamicContext, createWalletClientFromWallet } from "@dynamic-labs/sdk-react-core";

const App = () => {
  const { primaryWallet } = useDynamicContext();

  const signMessage = async () => {
    if (!primaryWallet) return;

    const walletClient = await createWalletClientFromWallet(primaryWallet);

    // No account is required by viem here, because the account is already setup.
    const signedMessage = await walletClient.signMessage({
      message: 'example message'

    console.log({ signedMessage })

  return (
    <button onClick={() => signMessage()}>
      Sign message

From the wallet client returned by the createWalletClientFromWallet, you can use it with other 3rd party packages that are viem compatible to interact with your primary wallet.