Skip to Content
🌐 Frontend SDKHooksExternal Wallet

External Wallet

Connect and interact with external wallets (MetaMask, WalletConnect) alongside EmbarkAI smart accounts.

EmbarkAI supports two wallet modes: linked (external wallet controls a smart account) and direct (use the external wallet directly). These hooks let you manage both modes.

Import

import { useWalletMode, useDirectWallet, useSendDirectTransaction, useTransferToLinkedWallet, } from '@embarkai/ui-kit'

useWalletMode

Returns the current wallet mode. In 'linked' mode, the external wallet is paired with an EmbarkAI smart account. In 'direct' mode, the external wallet is used as-is without account abstraction.

import { useWalletMode } from '@embarkai/ui-kit' function WalletModeIndicator() { const mode = useWalletMode() return ( <span> {mode === 'linked' ? 'Smart Account (AA)' : 'Direct Wallet'} </span> ) }

Return Value

ValueDescription
'linked'External wallet is linked to an EmbarkAI smart account. Transactions go through the bundler.
'direct'External wallet is used directly. No account abstraction.
nullNo external wallet connected.

useDirectWallet

Access the connected external wallet provider and address when in direct mode. Returns null if no external wallet is connected.

import { useDirectWallet } from '@embarkai/ui-kit' function DirectWalletInfo() { const wallet = useDirectWallet() if (!wallet) return <p>No external wallet connected.</p> return ( <div> <p>External address: {wallet.address}</p> <p>Connector: {wallet.connectorName}</p> </div> ) }

Return Value

PropertyTypeDescription
address`0x${string}`The external wallet address.
connectorNamestringName of the wallet connector (e.g., 'MetaMask', 'WalletConnect').
providerEIP1193ProviderThe raw EIP-1193 provider instance.

useSendDirectTransaction

Send a transaction directly from the external wallet, bypassing account abstraction. Useful when the user needs to interact with contracts that don’t support smart accounts.

import { useSendDirectTransaction } from '@embarkai/ui-kit' function DirectSend() { const { sendTransaction, isLoading, error, txHash } = useSendDirectTransaction() const handleSend = async () => { await sendTransaction({ to: '0xRecipientAddress...', value: '0.01', }) } return ( <div> <button onClick={handleSend} disabled={isLoading}> {isLoading ? 'Sending...' : 'Send (Direct)'} </button> {error && <p className="error">{error}</p>} {txHash && <p>Tx: {txHash}</p>} </div> ) }

Return Value

PropertyTypeDescription
sendTransaction(params: { to: string; value: string; data?: string }) => Promise<string | null>Submit a direct transaction. Returns the tx hash.
isLoadingbooleantrue while the transaction is pending.
errorstring | nullError message if the transaction failed.
txHashstring | nullThe transaction hash after submission.

useTransferToLinkedWallet

Transfer assets from the external wallet to the linked smart account. Only available in 'linked' mode.

import { useTransferToLinkedWallet } from '@embarkai/ui-kit' function FundSmartAccount() { const { transfer, isLoading, error, txHash } = useTransferToLinkedWallet() const handleTransfer = async () => { await transfer({ value: '0.5', }) } return ( <div> <button onClick={handleTransfer} disabled={isLoading}> {isLoading ? 'Transferring...' : 'Fund Smart Account'} </button> {error && <p className="error">{error}</p>} {txHash && <p>Funded! Tx: {txHash}</p>} </div> ) }

Parameters

ParameterTypeRequiredDescription
valuestringYesAmount of native token to transfer (human-readable).
tokenAddress`0x${string}`NoERC-20 token address. Omit for native token.
decimalsnumberNoToken decimals (required for ERC-20).

Return Value

PropertyTypeDescription
transfer(params) => Promise<string | null>Execute the transfer. Returns the tx hash.
isLoadingbooleantrue while the transfer is pending.
errorstring | nullError message if the transfer failed.
txHashstring | nullThe transaction hash after submission.

Full Example

import { useWalletMode, useDirectWallet, useTransferToLinkedWallet, } from '@embarkai/ui-kit' function ExternalWalletPanel() { const mode = useWalletMode() const wallet = useDirectWallet() const { transfer, isLoading } = useTransferToLinkedWallet() if (!wallet) return <p>Connect an external wallet to use these features.</p> return ( <div> <p>Mode: {mode}</p> <p>External: {wallet.address}</p> {mode === 'linked' && ( <button onClick={() => transfer({ value: '0.1' })} disabled={isLoading} > Fund Smart Account (0.1) </button> )} </div> ) }

Next Steps

Last updated on