Trustware.io
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: Embedded Wallet Deposit Mode description: Route deposits from a user's external wallet to their in-app embedded wallet. --- # Embedded Wallet Deposit Mode Users fund an in-app embedded wallet or smart account. Funds are routed from the user's external wallet (MetaMask, Coinbase Wallet, etc.) to their embedded wallet hosted by your application. ## Overview Embedded Wallet Deposit Mode solves a common onboarding challenge: users have funds in their external wallet, but your app uses embedded wallets (via Privy, Dynamic, Turnkey, or similar providers). This mode lets users deposit directly into their in-app wallet without manual bridging or transfers. **When to use this mode:** - Onboarding users with embedded wallet providers - Funding in-app balances or smart accounts - Top-ups for DEXs, social, gaming, or consumer applications - Any flow where users pay from an external wallet but funds should land in an app-controlled wallet ## How It Works ``` ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ User's EOA │ ──▶ │ Trustware │ ──▶ │ User's Embedded │ │(External Wallet)│ │ Routing Engine │ │ Wallet │ └─────────────────┘ └─────────────────┘ └─────────────────┘ USDT on USDC on Base Arbitrum (Privy/Dynamic/etc.) ``` The key difference from Swap/Bridge Mode: the destination is the user's **embedded wallet**, not their connected external wallet. This requires setting the destination address at runtime using `Trustware.setDestinationAddress()`. --- ## Core Concept: `setDestinationAddress()` Since embedded wallet addresses aren't known until the user authenticates with your app, you can't hardcode the destination in your config. Instead, you set it at runtime: ```typescript import { Trustware } from "@trustware/sdk"; // Call this once the embedded wallet address is available Trustware.setDestinationAddress("0x1234...abcd"); ``` This overrides any `toAddress` in your config and routes all subsequent transactions to the specified address. :::warning `setDestinationAddress()` must be called before the user initiates a deposit. If it's never called and `toAddress` is omitted from config, funds will route to the connected external wallet instead. ::: --- ## Basic Setup ### Step 1: Configure the Provider Set `autoDetectProvider: true` so the widget can detect the user's external wallet for payment. Omit `toAddress` - you'll set it at runtime. ```typescript import type { TrustwareConfigOptions } from "@trustware/sdk"; export const trustwareConfig: TrustwareConfigOptions = { apiKey: "your-api-key", routes: { toChain: "8453", // Base toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base defaultSlippage: 1, // toAddress intentionally omitted, set it at runtime }, autoDetectProvider: true, // Detect user's external wallet messages: { title: "Fund Your Account", description: "Deposit from any wallet to your in-app balance.", }, }; ``` ### Step 2: Set Destination When Embedded Wallet is Ready You need to call `setDestinationAddress()` once your embedded wallet provider returns the user's address. There are two approaches: --- ## Approach A: Listener Component Create a dedicated component that watches for the embedded wallet address and updates Trustware when it's available. ```typescript // components/DestinationBridge.tsx "use client"; import { useEffect } from "react"; import { Trustware } from "@trustware/sdk"; interface DestinationBridgeProps { address: string | undefined; } export function DestinationBridge({ address }: DestinationBridgeProps) { useEffect(() => { if (!address) return; Trustware.setDestinationAddress(address); }, [address]); return null; // This component renders nothing } ``` Then use it in your provider tree: ```typescript // app/providers.tsx "use client"; import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk"; import { usePrivy } from "@privy-io/react-auth"; import { DestinationBridge } from "@/components/DestinationBridge"; import { trustwareConfig } from "@/config/trustware"; export function DepositFlow() { const { user } = usePrivy(); const embeddedWalletAddress = user?.wallet?.address; return ( <TrustwareProvider config={trustwareConfig}> <DestinationBridge address={embeddedWalletAddress} /> <TrustwareWidget /> </TrustwareProvider> ); } ``` **Why this approach?** - Clean separation of concerns - Reusable across different pages - Easy to test in isolation --- ## Approach B: Inline Effect If you prefer fewer components, you can inline the effect directly in your deposit page: ```typescript // app/deposit/page.tsx "use client"; import { useEffect } from "react"; import { TrustwareProvider, TrustwareWidget, Trustware } from "@trustware/sdk"; import { usePrivy } from "@privy-io/react-auth"; import { trustwareConfig } from "@/config/trustware"; export default function DepositPage() { const { user } = usePrivy(); const embeddedWalletAddress = user?.wallet?.address; useEffect(() => { if (!embeddedWalletAddress) return; Trustware.setDestinationAddress(embeddedWalletAddress); }, [embeddedWalletAddress]); return ( <TrustwareProvider config={trustwareConfig}> <TrustwareWidget /> </TrustwareProvider> ); } ``` **Why this approach?** - Simpler for single-page implementations - All logic in one place - Fewer files to maintain --- ## Complete Example with Privy Here's a full implementation showing the complete provider stack: ```typescript // app/providers.tsx "use client"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { createConfig, http, WagmiProvider } from "wagmi"; import { base } from "wagmi/chains"; import { PrivyProvider } from "@privy-io/react-auth"; import { TrustwareProvider } from "@trustware/sdk"; import type { TrustwareConfigOptions } from "@trustware/sdk"; import { DestinationBridge } from "@/components/DestinationBridge"; const queryClient = new QueryClient(); const wagmiConfig = createConfig({ chains: [base], transports: { [base.id]: http() }, }); const trustwareConfig: TrustwareConfigOptions = { apiKey: process.env.NEXT_PUBLIC_TRUSTWARE_API_KEY!, routes: { toChain: String(base.id), toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base defaultSlippage: 1, }, autoDetectProvider: true, theme: { primaryColor: "#5555FF", backgroundColor: "#FFFFFF", borderColor: "#E5E5E5", secondaryColor: "#F5F5F5", textColor: "#333333", radius: 12, }, messages: { title: "Fund Your Account", description: "Deposit into your smart account to get started!", }, }; export default function Providers({ children }: { children: React.ReactNode }) { return ( <PrivyProvider appId={process.env.NEXT_PUBLIC_PRIVY_APP_ID!} config={{ embeddedWallets: { ethereum: { createOnLogin: "users-without-wallets" }, }, }} > <WagmiProvider config={wagmiConfig}> <QueryClientProvider client={queryClient}> <TrustwareProvider config={trustwareConfig}> {children} </TrustwareProvider> </QueryClientProvider> </WagmiProvider> </PrivyProvider> ); } ``` ```typescript // app/deposit/page.tsx "use client"; import { TrustwareWidget, Trustware } from "@trustware/sdk"; import { usePrivy } from "@privy-io/react-auth"; import { useEffect } from "react"; export default function DepositPage() { const { ready, authenticated, user } = usePrivy(); const embeddedWalletAddress = user?.wallet?.address; useEffect(() => { if (!embeddedWalletAddress) return; Trustware.setDestinationAddress(embeddedWalletAddress); }, [embeddedWalletAddress]); if (!ready) { return <div>Loading...</div>; } if (!authenticated) { return <div>Please sign in to deposit.</div>; } if (!embeddedWalletAddress) { return <div>Creating your wallet...</div>; } return ( <div> <p>Depositing to: {embeddedWalletAddress}</p> <TrustwareWidget /> </div> ); } ``` --- ## Using Other Embedded Wallet Providers The pattern is the same regardless of provider: get the embedded wallet address and pass it to `setDestinationAddress()`. ### Dynamic ```typescript import { useDynamicContext } from "@dynamic-labs/sdk-react-core"; import { Trustware } from "@trustware/sdk"; import { useEffect } from "react"; export function DynamicDepositFlow() { const { primaryWallet } = useDynamicContext(); const embeddedWalletAddress = primaryWallet?.address; useEffect(() => { if (!embeddedWalletAddress) return; Trustware.setDestinationAddress(embeddedWalletAddress); }, [embeddedWalletAddress]); return <TrustwareWidget />; } ``` ### Turnkey ```typescript import { useTurnkey } from "@turnkey/sdk-react"; import { Trustware } from "@trustware/sdk"; import { useEffect } from "react"; export function TurnkeyDepositFlow() { const { wallets } = useTurnkey(); const embeddedWalletAddress = wallets?.[0]?.address; useEffect(() => { if (!embeddedWalletAddress) return; Trustware.setDestinationAddress(embeddedWalletAddress); }, [embeddedWalletAddress]); return <TrustwareWidget />; } ``` --- ## Edge Cases ### Embedded Wallet Not Yet Created If the user hasn't completed onboarding and doesn't have an embedded wallet yet, `setDestinationAddress()` won't be called. Handle this by showing a loading state or prompting the user to complete signup: ```typescript if (!embeddedWalletAddress) { return ( <div> <p>Complete signup to get your wallet.</p> <SignupButton /> </div> ); } ``` ### `setDestinationAddress()` Never Called If `setDestinationAddress()` is never called and `toAddress` is omitted from config, the SDK falls back to the connected external wallet as the destination. This means: - User pays from EOA - User receives funds in EOA (not the embedded wallet) :::danger This fallback behavior can be confusing for users who expect funds in their in-app balance. Always ensure `setDestinationAddress()` is called before rendering the widget. ::: ### Address Changes Mid-Session If the embedded wallet address could change (e.g., user switches accounts), the `useEffect` pattern handles this automatically; it re-runs whenever the address changes and updates the destination. --- ## Configuration Reference | Parameter | Value for Embedded Wallet Mode | |-----------|-------------------------------| | `toAddress` | **Omit** from config - set via `setDestinationAddress()` | | `autoDetectProvider` | `true` - detect user's external wallet for payment | | `setDestinationAddress()` | **Required** - call when embedded wallet address is available | ### Full Config Options ```typescript const config: TrustwareConfigOptions = { apiKey: "your-api-key", routes: { toChain: "8453", toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", defaultSlippage: 1, // toAddress: DO NOT SET - use setDestinationAddress() instead }, autoDetectProvider: true, theme: { /* ... */ }, messages: { title: "Fund Your Account", description: "Deposit from any wallet.", }, }; ``` --- ## Summary | Step | Action | |------|--------| | 1 | Configure `TrustwareProvider` with `autoDetectProvider: true` | | 2 | Omit `toAddress` from config | | 3 | Get embedded wallet address from your provider (Privy, Dynamic, Turnkey) | | 4 | Call `Trustware.setDestinationAddress(address)` when address is available | | 5 | Render `TrustwareWidget` | → [Back to configuration modes / SDK OVERVIEW](https://hackmd.io/@trustware/B1zaIVkSbe)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully