Community Docs
  • 🏠Home
  • Getting Started
  • Introduction
    • What is Hyperliquid?
    • Hyperliquid Labs
    • Roadmap
      • 2025-26-03_Incident
  • Architecture
    • Overview
    • HyperBFT
      • API Servers
    • HyperCore
      • Dex
        • Clearinghouse
          • Margin Management
          • Liquidations
          • Funding
          • Fees
        • Order Book
        • Oracle
      • Vault
      • HIPs
        • Spot Deployments (HIP-1/HIP-2)
      • Bridge
    • HyperEVM
    • Hyperliquid.
      • Unit
  • Guide
    • User Guide
      • Onboarding
      • Spot Deployments
      • Airdrop
    • Builder Guide
      • HyperCore
        • Trading Bot
        • Builder Codes
          • Install Template
          • Update
        • Endpoints
          • Info
            • Spot
            • Perpetuals
          • Exchange
      • HyperEVM
        • EVM Basics
          • dApp Setup
        • Specificities
      • Node Operators
      • Historical Data
  • Ecosystem
    • The Hyper Liquidated
      • Community Map
    • Projects
      • Tools
      • HyperEVM
        • Felix
      • HyperCore
      • MemeCoin
Powered by GitBook
On this page
  • Option 1: Clone and Set Up the Repository
  • Option 2: Build from Scratch
  • 1. Install Next.js
  • 2. Project Structure
  • 3. Install & Configure Wagmi (Wallet Connection)
  • 4. UI & Styling Setup
  • 5. Blockchain Connection (Hyperliquid Integration)
  • 6. Agent-Based Trading
  • 7. Order Execution
  • 8. Final Steps: ESLint & Configuration
  • Conclusion
  1. Guide
  2. Builder Guide
  3. HyperCore
  4. Builder Codes

Install Template

PreviousBuilder CodesNextUpdate

Last updated 2 months ago

To get started, you can either clone the boilerplate repository for a quick setup or recreate it from scratch to better understand its structure.

πŸ”— Template Repository

You can find the template here:


Option 1: Clone and Set Up the Repository

1️⃣ Clone the Repository

Run the following command to clone the template:

git clone https://github.com/Solynor/create-builder-codes-dapp.git
cd create-builder-codes-dapp

Then install dependencies:

pnpm install  # or npm install

2️⃣ Change the Git Remote to Your Own Repository

To push your changes to a personal GitHub repository, update the remote URL:

git remote set-url origin git@github.com:your_name/repo_name.git

3️⃣ Configure the Environment Variables

Update the .env file with your custom settings - :

# The environment mode (development=testnet / production=mainnet) 
NEXT_PUBLIC_NODE_ENV=development

# The RPC URL for connecting to the HyperEVM  
NEXT_PUBLIC_RPC_URL=your_rpc_url  # [See RPC list on the doc]

# The builder's wallet address for fee collection  
NEXT_PUBLIC_BUILDER_ADDRESS=your_builder_address  # [Requires >100 USDC to enable the builder fee signer]

# The builder fee percentage (in basis points)  
NEXT_PUBLIC_BUILDER_FEE=10  # (0.1%)

# The WalletConnect project ID for wallet connections  
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_wallet_connect_project_id  # [Create your project ID here: https://docs.reown.com/cloud/relay]

4️⃣ Run the Application

Once everything is set up, start the development server:

pnpm dev  # or npm run dev

Your application should now be up and running!


Option 2: Build from Scratch

While cloning the boilerplate is faster, this approach helps you better understand the app’s architecture and dependencies.


1. Install Next.js

We’ll start by setting up a new Next.js 15 project.

πŸ“Œ Run the following command:

npx create-next-app@latest --use-pnpm
What is your project named? my-app
Would you like to use TypeScript? Yes
Would you like to use ESLint? Yes
Would you like to use Tailwind CSS? Yes
Would you like your code inside a `src/` directory? Yes
Would you like to use App Router? (recommended) Yes
Would you like to use Turbopack for `next dev`? Yes
Would you like to customize the import alias (`@/*` by default)? No
What import alias would you like configured? @/*

2. Project Structure

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.


3. Install & Configure Wagmi (Wallet Connection)

Wagmi is used for wallet connections and blockchain interactions.

πŸ“Œ Install dependencies:

pnpm add wagmi viem@2.x @tanstack/react-query

πŸ”§ Modify the following files:

πŸ“ lib/config/

  • index.ts β†’ Fetches configuration from .env

  • pnpm add @reown/appkit @reown/appkit-adapter-wagmi
  • chain.ts β†’ Defines the Hyperliquid EVM testnet

  • axios.ts β†’ Installs and configures Axios for API calls

    pnpm add axios

πŸ“ 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:

pnpm add zustand

Responsibilities of store.ts:

  1. Define user-related state types (User, Agent, UserStoreState).

  2. Create Zustand store for updating, resetting, and accessing user data globally.


4. UI & Styling Setup

πŸ“Œ Install required packages:

pnpm add tailwindcss-animate class-variance-authority clsx tailwind-merge lucide-react

Configure UI files

  • 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.


5. Blockchain Connection (Hyperliquid Integration)

Key Components:

πŸ“ 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/


6. Agent-Based Trading

Hyperliquid allows trading via an "agent" account.

Key Files:

  • 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.


7. Order Execution

Handles placing, signing, and submitting trades.

Key Services:

  • 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)

  • pnpm add @msgpack/msgpack

8. Final Steps: ESLint & Configuration

πŸ“Œ Update ESLint rules (eslint.config.mjs):

jsCopierModifierrules: {
  "@typescript-eslint/no-unused-vars": "warn",
  "@typescript-eslint/ban-ts-comment": "warn",
}

Conclusion

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 .

GitHub - create-builder-codes-dapp
RPC List
Next.js Installation Guide
Wagmi Documentation
AppKit Documentation
Zustand Documentation
shadcn/UI Installation Guide
Example
Example
Radix UI (Shadcn's Base Library)
API Docs
Hyperliquid Exchange API
MessagePack
example file
Dapp Setup Guide