Fund with Trails
Traditional funding flows require users to:- Find an external bridge or fiat onramp provider supported by the chain / app
- Swap to the required deposit token
- Pay multiple gas fees across different networks
- Wait for bridge confirmations
- Navigate complex interfaces
Use Cases
Funding flows in Trails are modeled as exact input by default. For example, “I have exactly 10 USDC tokens I want to send out from the origin chain, and I’ll receive 9.99 USDC on the destination.” Funding can done through a variety of methods such as the user’s connected wallet, an existing app they already have funds, or onramping from various fiat options. This is ideal for a variety of use cases and apps such as the following:- Transfer funds into a perpetual exchange deposit address.
- Bootstrap liquidity for lending protocols by transferring funds and executing a vault deposit.
- Add funds to your balance on an application with crypto support.
- Swap and deposit funds into staking contracts.
- Onboard users to new chains seamlessly from any origin chain.
- Top up a user’s account on a prediction market.
Examples
Depositing USDC into Polygon
This example shows how to use the Trails widget to enable a user to deposit into a chain with any token, in this case USDC on Polygon with a fixed amount:Depositing into a lending protocol
For protocols like Aave, Compound, and Fluid that are natively supported, use thelend composable action. This handles approval, the supply call, and dynamic amount resolution without encoding any calldata by hand:
useEarnMarkets to discover available market IDs rather than hard-coding them. See Markets and Providers.
Depositing into a vault
For ERC-4626 and vault-style protocols (Morpho, Yearn, SummerFi), use thedeposit composable action. The amount resolves at execution time so slippage and bridge output are handled automatically:
Depositing into a custom contract
If your target protocol is not covered by thelend or deposit builders, use TRAILS_ROUTER_PLACEHOLDER_AMOUNT in the widget’s toCalldata. The widget replaces this constant with the actual bridged/swapped output at execution time:
Creating a trustless deposit address via API (quote → commit → execute)
Deposit addresses are common flows where users can simply deposit funds into based on their requested quote and Trails will automatically orchestrate. The funding mode of the widget handles this for you, but in some cases you may wish to use the API to create your own deposit flows. To create a Trails deposit address, use the backend endpoints to create a quote, commit it, and then execute after the user deposits to the intent address returned in the quote. This gives you a trustless, deterministic deposit address and an intent lifecycle you can track server-side.Quotes expire after 10 minutes.
Next Steps
Explore more about configuring and customizing funding flows:-
Composable Actions - Programmatic DeFi deposits using
lend,deposit, andswapbuilders without the widget - Fund Mode Configuration - Complete configuration options and parameters for fund mode
- SDK Configuration - Widget setup, callbacks, and event handling
- Widget Theming - Customize the appearance to match your brand
- Hooks Reference - Available hooks for programmatic control
- Tokens & Chains - Configure supported tokens and destination chains
- Customization Guide - Advanced customization options for funding flows