UNPKG

create-bun-eth

Version:

Scaffold a Bun-first Ethereum project - Full-Stack dApp or Backend-Only API

239 lines (185 loc) โ€ข 6.73 kB
# create-bun-eth Scaffold a Bun-first Ethereum project - Full-Stack dApp or Backend-Only API. ## Usage ### Interactive Mode (Recommended) ```bash bunx create-bun-eth@latest my-project ``` You'll be prompted to choose: 1. **Full-Stack dApp** - Next.js frontend + Backend + Contracts 2. **Backend-Only** - API + Contracts only ### Non-Interactive Mode ```bash # Full-stack dApp bunx create-bun-eth@latest my-dapp --full-stack # Backend-only API bunx create-bun-eth@latest my-api --backend-only ``` ## Project Types ### Full-Stack dApp Perfect for building complete decentralized applications with a modern web interface. **Includes:** - ๐ŸŽจ **Next.js 14** - App Router with React 18 - ๐ŸŒˆ **RainbowKit** - Beautiful wallet connection UI - ๐Ÿ”— **wagmi v2** - React hooks for Ethereum - ๐ŸŽฃ **Custom Hooks** - `@bun-eth/hooks` for contract interactions - ๐Ÿงฑ **Web3 Components** - `@bun-eth/components` (Address, Balance, Faucet, etc.) - ๐Ÿ”ฅ **Contract Hot Reload** - Frontend auto-updates when contracts change - ๐Ÿ’ฐ **Burner Wallet** - Ephemeral wallet for local testing - ๐Ÿšฐ **Local Faucet** - Get test ETH instantly - ๐Ÿš€ **Elysia Backend** - Fast TypeScript API - ๐Ÿ“œ **Foundry Contracts** - Forge, Anvil, Cast - ๐Ÿณ **Docker Compose** - Full dev stack (Web + API + Anvil) **Services:** - Web UI: `http://localhost:3000` - API: `http://localhost:3001` - Anvil: `http://localhost:3002` ### Backend-Only Perfect for APIs, bots, scripts, or when you want to build your own custom frontend. **Includes:** - ๐Ÿš€ **Elysia Backend** - Fast TypeScript API - ๐Ÿ“œ **Foundry Contracts** - Forge, Anvil, Cast - ๐Ÿ“ฆ **TypeScript SDK** - Type-safe contract interactions - ๐Ÿณ **Docker Compose** - API + Anvil - โšก **Taskfile** - Command orchestration - ๐Ÿงช **Bun-Native Tests** - Testing for SDK/API **Services:** - API: `http://localhost:3001` - Anvil: `http://localhost:3002` ## Prerequisites - [Bun](https://bun.sh) >= 1.1.0 - [Foundry](https://getfoundry.sh/) - [Docker](https://www.docker.com/) - [Task](https://taskfile.dev/) (optional but recommended) ## Quick Start 1. **Create project:** ```bash bunx create-bun-eth@latest my-project ``` 2. **Navigate to project:** ```bash cd my-project ``` 3. **Complete setup** (installs deps, compiles contracts, runs tests): ```bash task setup ``` 4. **Start development stack:** ```bash task dev:up ``` 5. **Deploy contracts:** ```bash task contracts:deploy ``` 6. **Open browser** (Full-Stack only): ```bash open http://localhost:3000 ``` ## Available Commands ```bash # Setup & Development task setup # Complete setup with tests task dev:up # Start development stack task dev:down # Stop services task dev:logs # View all logs task dev:auto-ports # Find and configure free ports # Contracts task contracts:compile # Compile smart contracts task contracts:deploy # Deploy to local Anvil task contracts:test # Run Foundry tests task contracts:generate # Generate TypeScript types # Testing task test # Run all tests task test:contracts # Foundry tests only task test:api # API tests only task test:sdk # SDK tests only # Utilities task check:health # Check API health task status # View service status task --list # See all commands ``` ## Project Structure ### Full-Stack ``` my-dapp/ โ”œโ”€โ”€ apps/ โ”‚ โ”œโ”€โ”€ web/ # Next.js frontend โ”‚ โ””โ”€โ”€ api/ # Elysia backend โ”œโ”€โ”€ packages/ โ”‚ โ”œโ”€โ”€ contracts/ # Foundry smart contracts โ”‚ โ”œโ”€โ”€ hooks/ # Custom React hooks (@bun-eth/hooks) โ”‚ โ”œโ”€โ”€ components/ # Web3 UI components (@bun-eth/components) โ”‚ โ”œโ”€โ”€ burner-connector/ # Burner wallet connector โ”‚ โ”œโ”€โ”€ foundry-deployer/ # Hot reload system โ”‚ โ”œโ”€โ”€ core/ # Shared utilities & types โ”‚ โ””โ”€โ”€ sdk/ # TypeScript SDK โ”œโ”€โ”€ docker/ # Docker Compose setup โ””โ”€โ”€ tooling/task/ # Taskfile orchestration ``` ### Backend-Only ``` my-api/ โ”œโ”€โ”€ apps/api/ # Elysia backend โ”œโ”€โ”€ packages/ โ”‚ โ”œโ”€โ”€ contracts/ # Foundry smart contracts โ”‚ โ”œโ”€โ”€ core/ # Shared utilities & types โ”‚ โ””โ”€โ”€ sdk/ # TypeScript SDK โ”œโ”€โ”€ docker/ # Docker Compose setup โ””โ”€โ”€ tooling/task/ # Taskfile orchestration ``` ## Features ### Full-Stack Exclusive - **Contract Hot Reload**: Edit your contracts and watch your frontend auto-update - **Custom React Hooks**: Type-safe hooks with full TypeScript inference - `useScaffoldReadContract` - Read contract state with auto-refresh - `useScaffoldWriteContract` - Write to contracts with notifications - `useDeployedContractInfo` - Get contract addresses and ABIs - `useScaffoldEventHistory` - Subscribe to contract events - `useScaffoldEventSubscriber` - Real-time event streaming - **Web3 Components**: Pre-built UI components - `<Address />` - Display addresses with ENS, Blockie, copy, explorer link - `<Balance />` - Show ETH/token balances - `<Faucet />` - Local faucet for test ETH - `<BurnerWalletInfo />` - Burner wallet management UI - **Burner Wallet**: Ephemeral wallets for quick testing (localhost only) - **RainbowKit Integration**: Beautiful wallet connection UX ### Both Project Types - **Bun-Native**: 100% Bun, no Node.js required - **Foundry**: Blazing fast Solidity development - **TypeScript**: Full type safety across the stack - **Docker Compose**: Complete local dev environment - **Monorepo**: Clean package architecture - **Native Tests**: Bun tests for TS, Forge tests for Solidity ## Port Configuration By default, services use these ports: - Web: `3000` (Full-Stack only) - API: `3001` - Anvil: `8545` If ports are in use, run: ```bash task dev:auto-ports ``` This will automatically find free ports and update your `.env` file. ## Environment Variables Copy `.env.example` to `.env` (done automatically by `task setup`): ```bash # Ports (consecutive for easy management) WEB_PORT=3000 API_PORT=3001 ANVIL_PORT=3002 # API PORT=3001 NODE_ENV=development # Ethereum ANVIL_NODE=http://localhost:3002 CHAIN_ID=31337 PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # Frontend (Full-Stack only) NEXT_PUBLIC_WC_PROJECT_ID= # Get from https://cloud.walletconnect.com NEXT_PUBLIC_ANVIL_PORT=3002 ``` ## Documentation For full documentation, visit the [main repository](https://github.com/Bun-Eth-Community/bun-eth). ## License MIT