Skip to main content

getSignerForSmartWalletAccount

Gets a WalletClient instance for the EOA (Externally Owned Account) that owns the smart wallet account. This signer can be used to sign EVM transactions directly with the underlying EOA.

Usage

import { getSignerForSmartWalletAccount } from "@dynamic-labs-sdk/zerodev";
import { isEvmWalletAccount } from "@dynamic-labs-sdk/evm";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isEvmWalletAccount(walletAccount)) {
  const signer = await getSignerForSmartWalletAccount({
    smartWalletAccount: walletAccount,
  });

  // Use the signer to sign messages or transactions with the EOA
  const signature = await signer.signMessage({
    message: "Hello, World!",
  });
}

Parameters

ParameterTypeDescription
smartWalletAccountEvmWalletAccountThe smart wallet account to get the signer for
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<WalletClient> - A promise that resolves to a viem WalletClient instance for the EOA.

Errors

ErrorDescription
NoSmartWalletAccountSignerFoundErrorThrown when no signer wallet account is found for the given smart wallet account

React

import { getSignerForSmartWalletAccount } from '@dynamic-labs-sdk/zerodev';
import { isEvmWalletAccount } from '@dynamic-labs-sdk/evm';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';

function EoaSignButton() {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isEvmWalletAccount);
  const [signature, setSignature] = useState('');

  const handleSign = async () => {
    if (!walletAccount) return;
    const signer = await getSignerForSmartWalletAccount({ smartWalletAccount: walletAccount });
    const sig = await signer.signMessage({ message: 'Hello from the EOA signer' });
    setSignature(sig);
  };

  return (
    <div>
      <button onClick={handleSign} disabled={!walletAccount}>Sign with EOA</button>
      {signature && <p>Signature: {signature.slice(0, 20)}...</p>}
    </div>
  );
}