Install Template
Last updated
Last updated
To get started, you can either clone the boilerplate repository for a quick setup or recreate it from scratch to better understand its structure.
You can find the template here:
Run the following command to clone the template:
Then install dependencies:
To push your changes to a personal GitHub repository, update the remote URL:
Update the .env
file with your custom settings - :
Once everything is set up, start the development server:
Your application should now be up and running!
While cloning the boilerplate is faster, this approach helps you better understand the appβs architecture and dependencies.
Weβll start by setting up a new Next.js 15 project.
π Run the following command:
Your app will be structured as follows:
app/
Houses Next.js routes and pages.
Main entry point for the application.
components/
Stores reusable components for your pages.
hooks/
Contains custom React hooks for logic reuse (e.g., useAuth()
, useFetchData()
).
lib/
config/
β Global settings (e.g., API URLs, environment variables).
helpers/
β Utility functions (e.g., formatDate()
, parseCookies()
).
services/
β API call logic (e.g., authService.ts
, userService.ts
).
types/
β TypeScript interfaces for better type safety.
Wagmi is used for wallet connections and blockchain interactions.
π Install dependencies:
π lib/config/
index.ts
β Fetches configuration from .env
chain.ts
β Defines the Hyperliquid EVM testnet
axios.ts
β Installs and configures Axios for API calls
π components/
ContextProvider.tsx
β Wraps the app in WagmiProvider
and passes the config.
UserProvider.tsx
β Manages user state based on wallet connection (wagmi
+ localStorage
).
π Note: Consider improving Builder Fee storage (DB or blockchain instead of local cache).
π lib/store.ts
(State Management)
Zustand is used to manage global state efficiently.
π Install Zustand:
Responsibilities of store.ts
:
Define user-related state types (User
, Agent
, UserStoreState
).
Create Zustand store for updating, resetting, and accessing user data globally.
lib/utils.ts
β Utility functions for styling
components/ui/
β Copy & paste shadcn/UI components (e.g., toast.tsx
, button.tsx
, etc.).
π Important: shadcn/UI is not a component libraryβit's a collection of reusable UI components that you copy manually.
π app/page.tsx
Displays either the trading widget (if connected) or the wallet connection button.
π components/
ConnectWallet.tsx
β Wraps a Connect Wallet
button using AppKit.
Trade.tsx
β Trading widget for buying/selling assets.
π components/ApproveBuilderFee.tsx
Ensures users approve the Builder Fee before trading.
π lib/services/
approve-builder.ts
β Handles fee approval via Wagmi.
π lib/services/
Hyperliquid allows trading via an "agent" account.
components/ApproveAgent.tsx
Creates a new account (agent) for secure order placement without signing each time.
The agent cannot move user funds, making it a safer approach.
lib/services/approve-agent.ts
π Security Note: The agentβs private key is generated locallyβensure itβs never exposed or stored insecurely.
Handles placing, signing, and submitting trades.
market-order.ts
β /exchange
(trade execution)
mid-price.ts
β /info
(retrieves real-time mid-prices)
balances.ts
β /info
(fetches user balances)
token-details.ts
β /info
(retrieves token metadata)
π Update ESLint rules (eslint.config.mjs
):
By following this guide, youβve built the Builder Codes Dapp from scratch, gaining a deep understanding of:
β Next.js & TypeScript setup β Wallet connection & Wagmi configuration β API integration with Hyperliquid β Trading execution with agent-based security β UI & state management with shadcn/UI & Zustand
π Reference:
π Reference:
wagmi.ts
β Creates the Wagmi config using .
π Reference:
π Reference:
tailwind.config.ts
β Customize Tailwind settings ()
globals.css
β Define base styles ()
π Reference:
πΉ Setup Instructions: Refer to the documentation for detailed steps on integrating your Dapp with the blockchain.
builder-info.ts
β Calls Hyperliquid API /info
endpoint ().
Calls for agent approval.
signing.ts
β Uses for encoding.
π Modify Next.js config (next.config.ts
)
Check the .