A minimal starter showcasing Trails SDK flows in React: Fund, Pay, Swap, and Earn. It uses modern EVM tooling (Viem + Wagmi + RainbowKit), TanStack Query, Tailwind CSS, and radix components.
The onchain transaction rails for every token from every chain with every wallet with one, aggregated balance. Trails automatically detects and orchestrates the necessary steps in order to execute any cross-chain transaction with any token by swapping, bridging, and calling any arbitrary function. Integrate in seconds with only a few lines of code.
git clone https://github.com/0xsequence-demos/trails-nextjs-starter.git trails-nextjs-starter && cd trails-nextjs-starterpnpm i
# or: npm i | yarnCreate a .env file in the project root by copying the .env.example template, then set your Trails API key:
# Request an access key at https://t.me/build_with_trails
NEXT_PUBLIC_TRAILS_API_KEY="ADD_API_KEY_HERE"
# Optional walletconnect ID if you'd like walletconnect support, retrieved from https://cloud.walletconnect.com/.
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=Make sure to replace "ADD_YOUR_API_KEY_HERE" with your actual Trails API key — the project will not work without it.
pnpm dev
# or: npm run dev | yarn devOpen http://localhost:5173.
Each widget uses the same underlying TrailsWidget and differs by mode and a few props. See components/trails/*.tsx for concrete usage for each and UX flows.
This starter includes the TrailsProvider configured in components/Providers.tsx, which enables the use of Trails hooks throughout your app:
<TrailsProvider
config={{
trailsApiKey: process.env.NEXT_PUBLIC_TRAILS_API_KEY ?? "",
// Optional: Custom API endpoints
// trailsApiUrl: "...",
// sequenceIndexerUrl: "...",
// sequenceNodeGatewayUrl: "..."
}}
>
<App />
</TrailsProvider>See components/trails/TokenBalancesExample.tsx for a complete example using the useTokenBalances and useAccountTotalBalanceUsd hooks. This component:
- Fetches all token balances across chains for the connected wallet
- Displays total balance in USD
- Shows individual token balances with logos and USD values
Available hooks include:
useTokenBalances(address)- Fetch sorted token balances enriched with USD priceuseAccountTotalBalanceUsd(address)- Get total USD balance across tokensuseQuote()- Get real-time quotes for token swapsuseSupportedTokens()- Fetch supported tokens list
For more hooks and details, see the Trails Hooks documentation.
- Styling: Each widget supports
customCssvariables (https://docs.trails.build/sdk/theming). Common tokens:--trails-border-radius-button--trails-primary,--trails-primary-hover--trails-text-inverse--trails-focus-ring
- For advanced usage and prop reference, see the Trails docs (
https://docs.trails.build) - AI enabled wtih a
.cursorrulesfile and MCP server for Cursor or Claude available here.
