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

refreshWalletAccountShares(params: {
  accountAddress: string;
  chainName: string;
  walletMetadata: WalletMetadata;
  password?: string;
  externalServerKeyShares?: ServerKeyShare[];
  backUpToDynamic?: boolean;
}): Promise<{
  externalServerKeyShares: ServerKeyShare[];
  backupInfo: KeyShareBackupInfo;
}>

Description

Refreshes the wallet’s MPC key shares while maintaining the same threshold signature scheme. Returns both the new externalServerKeyShares and an updated backupInfo reflecting the new backup state. You must re-cache the backupInfo into your stored walletMetadata.externalServerKeySharesBackupInfo — otherwise subsequent operations read stale metadata.

Parameters

Required Parameters

  • accountAddress (string) - The wallet address (must include 0x prefix). Must match walletMetadata.accountAddress.
  • chainName (string) - The chain name (e.g., 'EVM')
  • walletMetadata (WalletMetadata) - The cached metadata for this wallet

Optional Parameters

  • password (string) - Required when backUpToDynamic is true. Used to encrypt the refreshed shares for Dynamic-managed backup.
  • externalServerKeyShares (ServerKeyShare[]) - Current plaintext shares. If omitted, the SDK recovers from backup using password.
  • backUpToDynamic (boolean) - Whether to back the new shares up to Dynamic’s key share service. Defaults to false.

Returns

  • Promise<{ externalServerKeyShares, backupInfo }>
    • externalServerKeyShares — The newly-generated shares. Re-vault these; the old shares no longer sign with this wallet.
    • backupInfo (KeyShareBackupInfo) — Updated backup-pointer state. Merge into your cached walletMetadata.

Example

import { authenticatedEvmClient } from './client';

const evmClient = await authenticatedEvmClient();

const walletMetadata = JSON.parse(await redis.get(`wallet:${accountAddress}`));
const externalServerKeyShares = await vault.read(`wallet:${accountAddress}/shares`);

const { externalServerKeyShares: refreshedShares, backupInfo } =
  await evmClient.refreshWalletAccountShares({
    accountAddress,
    chainName: 'EVM',
    walletMetadata,
    externalServerKeyShares,
    password: 'user-password',
    backUpToDynamic: true,
  });

// Re-cache the updated metadata and the new shares.
const updatedMetadata = {
  ...walletMetadata,
  externalServerKeySharesBackupInfo: backupInfo,
};
await redis.set(`wallet:${accountAddress}`, JSON.stringify(updatedMetadata));
await vault.write(`wallet:${accountAddress}/shares`, refreshedShares);

Error Handling

try {
  const result = await evmClient.refreshWalletAccountShares({
    accountAddress,
    chainName: 'EVM',
    walletMetadata,
    externalServerKeyShares,
    password: 'user-password',
    backUpToDynamic: true,
  });
  console.log('Wallet shares refreshed successfully');
} catch (error) {
  console.error('Failed to refresh wallet shares:', error);
}