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.
Summary
TheuseWalletDelegation hook provides methods to trigger and manage the wallet delegation flow for Dynamic embedded wallets.
For more information on how wallet delegation works, see the delegated access documentation.
The hook needs to be initialized within a child of DynamicContextProvider.
Return Value
The hook returns an object with the following properties:Functions
initDelegationProcess
Initiates the wallet delegation flow by opening the Dynamic modal and displaying the delegation prompt to the user.
Parameters:
options(optional): Configuration objectwallets(optional): Array of specific wallets to delegate. If not provided, delegates all eligible MPC wallets.
Promise<void> - Resolves when delegation completes successfully, rejects on failure.
Errors:
- Throws
"No primary wallet"if the user doesn’t have a primary wallet connected - Throws
"user_not_logged_in"if the user is not authenticated
shouldPromptWalletDelegation
Determines whether the user should be prompted for wallet delegation based on:
- Delegated access settings in project configuration
- User’s previous delegation decisions (denied or completed)
- Existence of undelegated MPC wallets
boolean - true if the user should see the delegation prompt, false otherwise.
Example:
getWalletsDelegatedStatus
Returns the delegation status of all MPC wallets for the current user.
Returns: An array of objects containing:
address: string - The wallet addresschain: string - The chain the wallet is onstatus: WalletDelegationStatus - The delegation status (‘delegated’, ‘pending’, or ‘not_delegated’)
delegateKeyShares
Delegates key shares for one or more wallets. This allows your application to act on behalf of the user’s wallet (see Delegated Access).
Parameters:
wallets(optional): Array of wallet objects to delegate. Each wallet object should have:chainName: ChainEnum - The chain the wallet is associated withaccountAddress: string - The address of the wallet to delegate
wallets is not provided or is empty, the function will delegate all pending wallets eligible for delegation.
Returns: Promise resolving to void on success. The function automatically refreshes user data after delegation completes.
Errors: Throws DelegationError when one or more per-wallet delegations fail. The hook still attempts every wallet and still calls refresh — the error is thrown after the loop with the full set of successful and failed wallets attached, so callers can decide what to retry.
Example:
- Delegates wallets sequentially (one at a time)
- Continues iterating even if individual wallets fail
- Always refreshes user data after the loop (even on partial failure) so wallet state stays in sync
- Throws a single
DelegationErrorat the end if any per-wallet delegation failed
revokeDelegation
Revokes delegation for one or more wallets. This removes your application’s ability to act on behalf of the user’s wallet (see Revoking Delegation).
Parameters:
wallets: Array of wallet objects to revoke. Each wallet object should have:chainName: ChainEnum - The chain the wallet is associated withaccountAddress: string - The address of the wallet to revokestatus: WalletDelegationStatus - The delegation status of the wallet (must be ‘delegated’ for revocation to proceed)
DelegationError when one or more per-wallet revocations fail. The hook still attempts every wallet and still calls refresh — the error is thrown after the loop.
Example:
- Revokes wallets sequentially (one at a time)
- Only attempts to revoke wallets with status ‘delegated’ (logs a warning and skips others)
- Continues iterating even if individual revocations fail
- Always refreshes user data after the loop (even on partial failure) so wallet state stays in sync
- Throws a single
DelegationErrorat the end if any per-wallet revocation failed
denyWalletDelegation
Permanently denies wallet delegation for the current user. This sets a flag that prevents the delegation prompt from appearing again, even if the user has undelegated wallets.
Returns: void
Example:
dismissDelegationPrompt
Temporarily dismisses the delegation prompt for the current session. Unlike denyWalletDelegation, this does not permanently prevent the prompt from appearing - it will show again in future sessions.
Returns: void
Example:
clearDelegationSessionState
Clears all delegation-related session state, including any “denied” or “dismissed” flags. This resets the delegation prompt behavior, allowing it to appear again based on the user’s wallet status.
Returns: void
Example:
DelegationError
Thrown by delegateKeyShares and revokeDelegation when one or more per-wallet operations fail. Extends AggregateError, so callers reading the underlying causes via .errors keep working; structured fields make it easy to drive partial-failure UI without parsing the message.
Fields:
operation:'delegate' | 'revoke'— which method threw.successfulWallets:{ chainName: ChainEnum; accountAddress: string }[]— wallets that completed before the error was thrown.failedWallets:{ wallet: { chainName: ChainEnum; accountAddress: string }; cause: unknown }[]— wallets that failed and their underlying causes.successCount:number— convenience getter.failureCount:number— convenience getter.message:string—"Delegation failed for X of Y wallet(s): <first underlying cause>"(or"Revoke delegation failed for ..."for revocations).
Properties
delegatedAccessEnabled
A boolean value from your project settings that indicates whether delegated access is enabled for your application.
Type: boolean | undefined
Example:
requiresDelegation
A boolean value from your project settings that indicates whether wallet delegation is required for your application.
Type: boolean | undefined
Example:
Usage
Advanced Usage
Delegate specific wallets:Important Notes
- The user must be authenticated and have a primary wallet for delegation to work
- The delegation modal is part of the Dynamic UI and handles all user interactions
- User delegation preferences are persisted across sessions using local storage