Skip to main content

Summary

A React hook that provides functionality for managing Dynamic WaaS (Wallet as a Service) wallets. This hook enables wallet creation, management, and interaction with Dynamic’s embedded wallet system.

Return Value

Functions

createWalletAccount

Creates wallet accounts for enabled chains in the project settings. This function can create wallets for one or more specified chains.
Parameters:
  • chainNames: ChainEnum[] - Creates a wallet only for the specified chains.
Returns: Promise resolving to an array of created wallet accounts. Each wallet account in the array will have the following structure:
Behavior:
  • Creates wallet accounts for the specified chains in parallel
  • After creation, it will:
    1. Find the primary wallet account (based on the chain marked as primary in settings)
    2. Refresh the user data to get the latest wallet information
    3. Update the primary wallet to the newly created wallet
    4. Close any open auth flow modals
Throws:
  • NO_ENABLED_CHAINS_ERROR if no chains are enabled in the project settings
  • DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR if a wallet connector is not found for an enabled chain
  • Any errors from the underlying wallet creation process
Example:

getWalletConnector

Retrieves a configured wallet connector for a specific chain.
Parameters:
  • chainName: string - The name of the chain to get the connector for.
Returns: A configured IDynamicWaasConnector or undefined if:
  • Cookie auth is disabled and no auth token is present
  • No wallet connector options are available
  • The environment ID is not set
Throws:
  • DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR if the wallet connector is not found.

importPrivateKey

Imports a private key for a specific chain.
Parameters:
  • chainName: string - The name of the chain to import the private key for.
  • privateKey: string - The private key to import.
Behavior:
  • Imports the private key for the specified chain
  • Refreshes the user data after successful import
  • Returns undefined if the wallet connector is not found

getWaasWallets

Finds all Dynamic WaaS wallets associated with the user.
Returns: Array of Dynamic WaaS wallets. Each wallet in the array will have the following structure:
Behavior:
  • Filters the user’s wallets to only return those with key === 'dynamicwaas'
  • Returns an empty array if no Dynamic WaaS wallets are found
  • The returned wallets can be used for chain-specific operations (e.g., transactions)
Example:

Properties

dynamicWaasIsEnabled

Indicates whether Dynamic WaaS is enabled in the project settings.

shouldAutoCreateDynamicWaasWallet

Indicates whether a Dynamic WaaS wallet should be automatically created.

Important Notes

  1. Authentication Requirements:
    • The hook requires either cookie authentication or a valid auth token to function properly.
    • Wallet connector operations will return undefined if authentication is not available.
  2. Chain Configuration:
    • Wallet creation and operations require properly configured chains in the project settings.
    • At least one chain must be enabled for wallet creation to work.
  3. Version Compatibility:
    • Dynamic WaaS is only enabled when using EmbeddedWalletVersionEnum.V3.
    • The hook will not function with older wallet versions (V1 or V2).
  4. Auto-Creation Behavior:
    • Auto-creation of wallets is controlled by project settings.
    • Separate settings exist for external wallet users.
    • Auto-creation will not occur if the user already has a Dynamic WaaS wallet.
  5. Relay Configuration:
    • The hook uses a relay URL for wallet operations, which can be configured in project settings.
    • If not specified, it defaults to ‘relay.dynamic-preprod.xyz’.

Example Usage