Overview
Fund mode implements input-driven deposit flows where users select the amount they want to send. The widget routes funds from any supported chain and token to the destination automatically. Trade type:EXACT_INPUT — user specifies input amount, variable output after fees.
Quick start
Fund supports four payment methods: connected wallet, crypto transfer (QR/address), fiat on-ramp, and exchange (CEX). SetpaymentMethod to open a specific flow, or omit it to let the user choose.
The exchange (CEX) flow requires your app to be added to the allowlist. Contact us to get access.
paymentMethod values and the from options each accepts.
Props
Required
Destination (optional)
Source selection (optional)
SetpaymentMethod to control how the user funds:
The
from prop is fully typed based on the selected paymentMethod. TypeScript will narrow the allowed fields automatically, so only valid options for that method are accepted.
When paymentMethod is set, the from object applies to that method:
Fund method list (optional)
Control which funding methods are shown to the user:Lifecycle callbacks
Examples
Buy crypto with a credit card
Transfer from a CEX
QR code / address deposit
Restrict to specific funding methods
Show only fiat and exchange onramps, hide the rest:Exchange onramp
Users can transfer directly from a CEX account (Coinbase, Binance, Robinhood, and others) without leaving your app. The OAuth connection and transfer are handled automatically — Trails receives the funds and routes them to the destination. No separate account or additional API keys are required. Pass theonramp prop to enable the exchange flow. At minimum, set environment:
exchanges array:
environment: 'sandbox'. A yellow banner is shown inside the widget when sandbox is active.
How the auth flow works:
- User selects an exchange from the list.
- An OAuth popup opens to the exchange’s login.
- After authentication, a transfer confirmation is shown with the amount, token, and destination.
- User confirms and the withdrawal is initiated from their exchange account.
- Once detected on-chain, Trails routes the funds to the destination.
- Exchange list is empty — confirm
apiKeyis valid; the exchange list fetch requires a valid API key. - Popup blocked — trigger the flow from a user gesture (button click) rather than programmatically, and encourage users to allow popups for your domain.
- Session expired — the exchange session is valid for 5 minutes; a “Refresh Session” button appears if it expires.
Protocol deposit with dynamic calldata
For ERC-4626 vaults and staking contracts where the deposit amount is a function parameter, useTRAILS_ROUTER_PLACEHOLDER_AMOUNT. Trails replaces it with the actual bridged/swapped output at execution time.
Use
TRAILS_ROUTER_PLACEHOLDER_AMOUNT when the deposit amount is a function parameter and the user selects the amount. Do not use it for functions that read balance internally (e.g. depositAll()).See also
- Fund use cases — protocol deposits, trustless deposit addresses
- Composable actions — programmatic DeFi deposits
- Configuration reference — full prop list