Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

Function Signature

createWalletAccount(params: {
  thresholdSignatureScheme: ThresholdSignatureScheme;
  password?: string;
  onError?: (error: Error) => void;
  backUpToDynamic?: boolean;
}): Promise<{
  walletMetadata: WalletMetadata;
  publicKeyHex: string;
  rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
  externalServerKeyShares: ServerKeyShare[];
  externalKeySharesWithBackupStatus: Array<{
    share: ServerKeyShare;
    backedUpToClientKeyShareService: boolean;
  }>;
}>

Description

Creates a new EVM wallet account with the specified threshold signature scheme. Returns a walletMetadata object (non-sensitive identity + backup pointers) alongside the sensitive externalServerKeyShares. Persist bothwalletMetadata in your cache (Redis/Postgres) and externalServerKeyShares in a secrets vault. The SDK is stateless and you must pass walletMetadata to every subsequent operation.

Parameters

Required Parameters

  • thresholdSignatureScheme (ThresholdSignatureScheme) - The threshold signature scheme for the wallet

Optional Parameters

  • password (string) - Password to protect the wallet’s key shares. Required when backUpToDynamic is true. You can use the same password for all wallets or a unique password per wallet.
  • onError ((error: Error) => void) - Error callback function
  • backUpToDynamic (boolean) - Whether to back up the first key share to Dynamic’s client share service (defaults to false). When true, the first share is backed up to Dynamic and the remaining shares are returned for external storage. When false, all shares are returned for external storage. When true, a password must be provided.

Returns

  • Promise<object> - Object containing wallet information:
    • walletMetadata (WalletMetadata) - Non-sensitive identity + backup-pointer metadata. The wallet’s address is at walletMetadata.accountAddress, and walletMetadata.walletId is the unique wallet identifier. Persist this in your cache.
    • publicKeyHex - Public key in hex format
    • rawPublicKey - Raw public key object
    • externalServerKeyShares (ServerKeyShare[]) - Sensitive plaintext shares for MPC operations. Store these in a secrets vault.
    • externalKeySharesWithBackupStatus - Array of key shares with their backup status. Each entry contains:
      • share - The key share (ServerKeyShare)
      • backedUpToClientKeyShareService - Whether this share was backed up to Dynamic’s client share service

Example

import { authenticatedEvmClient } from './client';
import { ThresholdSignatureScheme } from '@dynamic-labs-wallet/node';

const evmClient = await authenticatedEvmClient();

const { walletMetadata, externalServerKeyShares, externalKeySharesWithBackupStatus } =
  await evmClient.createWalletAccount({
    thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_THREE,
    password: 'your-password',
    backUpToDynamic: true,
  });

console.log('Wallet created:', walletMetadata.accountAddress);

// Persist the metadata in your cache and the shares in your secrets vault.
await redis.set(`wallet:${walletMetadata.accountAddress}`, JSON.stringify(walletMetadata));
await vault.write(`wallet:${walletMetadata.accountAddress}/shares`, externalServerKeyShares);

// Each share includes its backup status
for (const { share, backedUpToClientKeyShareService } of externalKeySharesWithBackupStatus) {
  console.log('Share backed up to Dynamic:', backedUpToClientKeyShareService);
  if (!backedUpToClientKeyShareService) {
    // Store this share securely — it is not backed up by Dynamic
  }
}

Error Handling

try {
  const wallet = await evmClient.createWalletAccount({
    thresholdSignatureScheme: ThresholdSignatureScheme.TWO_OF_TWO,
    onError: (error) => console.error('Wallet creation error:', error),
  });
  console.log('Wallet created successfully');
} catch (error) {
  console.error('Failed to create wallet:', error);
}