Skip to main content

Overview

Use getWalletClient to create a Viem WalletClient for your server wallet. This allows you to interact with EVM chains using Viem’s familiar API for signing messages, transactions, and typed data.

Prerequisites

  • A Dynamic server wallet (see Server Wallets Overview)
  • @dynamic-labs-wallet/node-evm installed
  • An authenticated DynamicEvmWalletClient instance

Usage

Basic example

import { DynamicEvmWalletClient } from '@dynamic-labs-wallet/node-evm';

const evmClient = new DynamicEvmWalletClient({
  environmentId: 'your-environment-id',
});

await evmClient.authenticateApiToken('your-api-token');

// Get a Viem wallet client
const walletClient = await evmClient.getWalletClient({
  accountAddress: '0x1234567890123456789012345678901234567890',
  chainId: 11155111, // Sepolia
  rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
});

// Use the wallet client
const chainId = await walletClient.getChainId();
console.log('Chain ID:', chainId);

With external server key shares

If you’re storing key shares externally, pass them when creating the wallet client:
const walletClient = await evmClient.getWalletClient({
  accountAddress: '0x1234567890123456789012345678901234567890',
  externalServerKeyShares: keyShares, // From wallet creation
  chainId: 11155111,
  rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
});

With password protection

For password-protected wallets:
const walletClient = await evmClient.getWalletClient({
  accountAddress: '0x1234567890123456789012345678901234567890',
  password: 'your-wallet-password',
  chainId: 11155111,
  rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
});

Using Viem chain objects

You can pass a Viem Chain object directly instead of chainId and rpcUrl:
import { mainnet, sepolia } from 'viem/chains';

const walletClient = await evmClient.getWalletClient({
  accountAddress: '0x1234567890123456789012345678901234567890',
  chain: sepolia,
});

Custom chain configuration

For custom or unsupported chains, use chainId and rpcUrl:
const walletClient = await evmClient.getWalletClient({
  accountAddress: '0x1234567890123456789012345678901234567890',
  chainId: 12345, // Custom chain ID
  rpcUrl: 'https://custom-chain-rpc.example.com',
});
When providing chainId, you must also provide rpcUrl. The chain will be automatically configured with default ETH currency settings.

Common operations

Sign a message

const message = 'Hello from Dynamic Wallet SDK!';
const signature = await walletClient.signMessage({ message });
console.log('Signature:', signature);

Sign typed data

const signature = await walletClient.signTypedData({
  domain: {
    name: 'Dynamic Wallet Demo',
    version: '1',
    chainId: walletClient.chain.id,
  },
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' },
    ],
  },
  primaryType: 'Person',
  message: {
    name: 'Alice',
    wallet: accountAddress as `0x${string}`,
  },
});

Send a transaction

const hash = await walletClient.sendTransaction({
  to: '0x0000000000000000000000000000000000000000',
  value: BigInt(1000000000000000), // 0.001 ETH
});
console.log('Transaction hash:', hash);

Parameters

ParameterTypeRequiredDescription
accountAddressstringYesThe wallet address to create a client for.
passwordstringNoPassword for password-protected wallets.
externalServerKeySharesServerKeyShare[]NoExternal key shares if stored outside Dynamic’s service.
chainChainNoViem chain object. Takes precedence over chainId and rpcUrl.
chainIdnumberNoChain ID. Requires rpcUrl when provided.
rpcUrlstringNoRPC URL for the chain. Required when chainId is provided.
If no chain configuration is provided, the wallet client defaults to Ethereum mainnet.

Return value

Returns a Viem WalletClient<Transport, Chain, Account> instance with the following properties:
  • account - The wallet account adapter
  • chain - The configured chain
  • transport - HTTP transport for RPC calls
The wallet client supports all standard Viem wallet client methods including signMessage, signTypedData, sendTransaction, and more.