Skip to main content

Function Signature

createDelegatedEvmWalletClient(config: {
  environmentId: string;
  apiKey: string;
  baseApiUrl?: string;
  baseMPCRelayApiUrl?: string;
  debug?: boolean;
}): DelegatedEvmWalletClient

Description

Creates a delegated EVM wallet client instance that can be used to perform signing operations on behalf of users who have granted delegation permission. The client uses your server API key for authentication and can work with multiple wallets by accepting wallet-specific credentials for each operation. This function follows a functional programming paradigm where you create the client once and reuse it for multiple signing operations across different users.

Parameters

Required Parameters

  • environmentId (string) - Your Dynamic environment ID from the Dynamic dashboard
  • apiKey (string) - Your server API key for server-to-server authentication

Optional Parameters

  • baseApiUrl (string) - Custom Dynamic API URL. Defaults to https://app.dynamic.xyz
  • baseMPCRelayApiUrl (string) - Custom MPC relay service URL. Defaults to https://mpc-relay.dynamic.xyz
  • debug (boolean) - Enable debug logging. Defaults to false

Returns

DelegatedEvmWalletClient - A client instance that can be used with delegated signing functions. The client has the following properties:
  • chainName: Always 'EVM' for this client type
  • environmentId: Your environment ID
  • apiKey: Your server API key (used internally)
  • Additional internal properties for API communication

Example

Basic Usage

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

const delegatedClient = createDelegatedEvmWalletClient({
  environmentId: 'your-environment-id',
  apiKey: 'your-server-api-key',
});

With All Options

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

const delegatedClient = createDelegatedEvmWalletClient({
  environmentId: process.env.DYNAMIC_ENVIRONMENT_ID!,
  apiKey: process.env.DYNAMIC_API_KEY!,
  baseApiUrl: 'https://custom-api.example.com',
  baseMPCRelayApiUrl: 'https://custom-mpc-relay.example.com',
  debug: process.env.NODE_ENV === 'development',
});

Singleton Pattern

import { createDelegatedEvmWalletClient } from '@dynamic-labs-wallet/node-evm';
import type { DelegatedEvmWalletClient } from '@dynamic-labs-wallet/node-evm';

let clientInstance: DelegatedEvmWalletClient | null = null;

export function getDelegatedClient(): DelegatedEvmWalletClient {
  if (!clientInstance) {
    clientInstance = createDelegatedEvmWalletClient({
      environmentId: process.env.DYNAMIC_ENVIRONMENT_ID!,
      apiKey: process.env.DYNAMIC_API_KEY!,
    });
  }
  return clientInstance;
}

Type Definitions

type DelegatedEvmWalletClient = DelegatedWalletClient & {
  readonly chainName: 'EVM';
};

type DelegatedEvmClientConfig = {
  environmentId: string;
  baseApiUrl?: string;
  baseMPCRelayApiUrl?: string;
  apiKey: string;
  debug?: boolean;
};

Security Considerations

  • API Key Protection: Never expose your server API key in client-side code or public repositories
  • Environment Variables: Store API keys in secure environment variables
  • Key Rotation: Implement regular API key rotation policies
  • Access Control: Limit API key permissions to only what’s necessary

Error Handling

try {
  const delegatedClient = createDelegatedEvmWalletClient({
    environmentId: process.env.DYNAMIC_ENVIRONMENT_ID!,
    apiKey: process.env.DYNAMIC_API_KEY!,
  });
  console.log('Client created successfully');
} catch (error) {
  console.error('Failed to create delegated client:', error);
}
I