Skip to content

Bun-Eth-Community/eth-crowdsale

Repository files navigation

Bun-Eth

A Bun-first scaffold for Ethereum projects

License: MIT Bun TypeScript

A pure Bun-native monorepo template for building Ethereum-based applications. Replace scaffold-eth-2's Node/React stack with a modern, TypeScript-first approach using Bun, Elysia, and Foundry.

Token Crowdsale

✨ Features

  • πŸ”₯ Contract Hot Reload - Your frontend auto-adapts to your smart contracts as you deploy them
  • 🎣 Custom Hooks - Type-safe React hooks for reading, writing, and watching contracts (@bun-eth/hooks)
  • 🧱 Web3 Components - Pre-built UI components for addresses, balances, inputs, and more (@bun-eth/components)
  • πŸ’° Burner Wallet - Ephemeral wallets for instant testing without MetaMask
  • 🚰 Local Faucet - Built-in faucet for quick testing on Anvil
  • 🌈 RainbowKit - Beautiful wallet connection UI with multi-wallet support
  • πŸš€ Bun-Native - 100% Bun, no Node.js required - lightning fast builds
  • ⚑ Elysia Backend - Fast, TypeScript-first web framework for REST API
  • 🎨 Next.js Frontend - Modern React framework with shadcn/ui components
  • πŸ”¨ Foundry Contracts - Blazing fast Rust-based smart contract framework (Forge + Anvil)
  • 🐳 Docker Compose - Complete local development environment
  • πŸ“¦ Clean Monorepo - Well-architected packages with clear separation of concerns
  • πŸ§ͺ Comprehensive Testing - Bun tests for TypeScript, Foundry tests for Solidity
  • πŸ”§ Taskfile - Powerful command orchestration
  • πŸ’Ž Full TypeScript - Type safety from contracts to UI

πŸš€ Quick Start

Using the CLI (Recommended)

bunx create-bun-eth@latest my-dapp
cd my-dapp
task setup

Manual Clone

git clone https://github.com/Bun-Eth-Community/bun-eth.git my-dapp
cd my-dapp
task setup

The setup task will:

  • Create .env from .env.example
  • Install all dependencies
  • Compile smart contracts
  • Run all tests to verify everything works

πŸ“‹ Prerequisites

  • Bun >= 1.1.0
  • Foundry (for smart contracts)
  • Docker (for local Ethereum node)
  • Task (optional, for orchestration)

Install Task

# macOS
brew install go-task

# Linux
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin

# Or use bunx
bunx @go-task/cli

πŸ“Έ Screenshots

The project includes a stunning 3D animated crowdsale interface with multiple states and responsive design.

Key Features

  • 3D Animated Hero - Eye-catching title with gradient effects and floating particles
  • Status Indicators - Clear visual feedback for all crowdsale states (not deployed, loading, active, ended)
  • Real-time Data - Live blockchain data updates with animated stats
  • Responsive Design - Optimized for desktop, tablet, and mobile devices

View All Screenshots

For detailed screenshots of all UI states, responsive views, and individual sections, see docs/SCREENSHOTS.md.

πŸ—οΈ Project Structure

bun-eth/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                         # Elysia backend API
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts            # API entry point
β”‚   β”‚   β”‚   β”œβ”€β”€ config.ts           # Configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ provider.ts         # Ethereum provider setup
β”‚   β”‚   β”‚   └── routes/             # API routes
β”‚   β”‚   └── Dockerfile
β”‚   └── web/                         # Next.js frontend
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ app/                # App router pages
β”‚       β”‚   β”œβ”€β”€ components/         # Local components
β”‚       β”‚   └── lib/                # Utilities & wagmi config
β”‚       └── package.json
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ contracts/                   # Smart contracts (Foundry)
β”‚   β”‚   β”œβ”€β”€ contracts/              # Solidity files
β”‚   β”‚   β”œβ”€β”€ script/                 # Deploy scripts
β”‚   β”‚   β”œβ”€β”€ test/                   # Foundry tests
β”‚   β”‚   β”œβ”€β”€ deployedContracts.ts    # πŸ”₯ Auto-generated (hot reload!)
β”‚   β”‚   └── foundry.toml
β”‚   β”œβ”€β”€ hooks/                       # 🎣 React hooks for Web3
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ useScaffoldContract.ts
β”‚   β”‚       β”œβ”€β”€ useScaffoldReadContract.ts
β”‚   β”‚       β”œβ”€β”€ useScaffoldWriteContract.ts
β”‚   β”‚       └── ...                 # 10+ hooks
β”‚   β”œβ”€β”€ components/                  # 🧱 Web3 UI components
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ Address.tsx
β”‚   β”‚       β”œβ”€β”€ Balance.tsx
β”‚   β”‚       β”œβ”€β”€ Faucet.tsx
β”‚   β”‚       └── ...                 # 10+ components
β”‚   β”œβ”€β”€ foundry-deployer/            # πŸ”₯ Hot reload system
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ generator.ts        # Generates deployedContracts.ts
β”‚   β”‚       └── cli.ts              # CLI tool
β”‚   β”œβ”€β”€ core/                        # Shared utilities
β”‚   β”œβ”€β”€ sdk/                         # TypeScript SDK for API
β”‚   └── create-bun-eth/              # Scaffolding CLI
β”œβ”€β”€ tooling/
β”‚   └── task/
β”‚       └── Taskfile.yml            # Task definitions
└── docker/
    └── docker-compose.yml          # Anvil + API + Web

πŸ› οΈ Development

Start Development Stack

task dev:up

This command intelligently starts all services with health checks:

  • Anvil local Ethereum node on http://localhost:3002
  • Bun-Eth API on http://localhost:3001
  • Next.js Web UI on http://localhost:3000

Features:

  • βœ… Verifies each service is actually responding before reporting success
  • ⏳ Shows clear waiting indicators for each service
  • ❌ Exits with error if any service fails to start (with troubleshooting tips)
  • πŸ“ Only displays service URLs when they're confirmed to be working

The command will:

  1. Start Docker services (Anvil + API)
  2. Start Web dev server
  3. Wait up to 30 seconds for each service to respond
  4. Display success with service URLs, or fail with helpful error messages

Check Service Status

task status

Displays real-time status of all services with health checks:

  • Shows Docker container status
  • Tests HTTP endpoints for Web and API
  • Tests JSON-RPC for Anvil node
  • Clearly indicates which services are healthy (βœ…) or not responding (❌)

Start Web UI Only

task web:dev

This starts the Next.js frontend on http://localhost:3000

Stop Development Stack

task dev:down

Stops all services cleanly (Docker containers + Web dev server).

View Logs

# All services
task dev:logs

# API only
task dev:logs:api

# Anvil node only
task dev:logs:anvil

# Web dev server only
task dev:logs:web

πŸ“œ Smart Contracts

Compile Contracts

task contracts:compile

Deploy Contracts

# Deploy to local network
task contracts:deploy

# Deploy to Sepolia
task contracts:deploy:sepolia

Test Contracts

task contracts:test

🌐 API Endpoints

Base URL: http://localhost:3001

Health Check

GET /health

Response:

{
  "status": "ok",
  "timestamp": 1234567890,
  "version": "0.1.0",
  "network": {
    "chainId": 31337,
    "blockNumber": 42
  }
}

Get Wallet Info

GET /wallet/:address

Response:

{
  "address": "0x...",
  "balance": "10.5",
  "nonce": 5
}

Send Transaction

POST /wallet/send
Content-Type: application/json

{
  "to": "0x...",
  "value": "1.0",
  "data": "0x..."
}

Call Contract (Read)

POST /contract/call
Content-Type: application/json

{
  "contractAddress": "0x...",
  "method": "retrieve",
  "args": []
}

Send Contract Transaction (Write)

POST /contract/send
Content-Type: application/json

{
  "contractAddress": "0x...",
  "method": "store",
  "args": [42],
  "value": "0"
}

🌐 Frontend Development

The Next.js frontend includes:

  • shadcn/ui - Beautiful, accessible components built on Radix UI
  • wagmi - React Hooks for Ethereum
  • viem - TypeScript Ethereum library
  • Tailwind CSS - Utility-first CSS framework

Web Tasks

# Start development server
task web:dev

# Build for production
task web:build

# Start production server
task web:start

Wallet Integration

The frontend supports:

  • MetaMask and other injected wallets
  • WalletConnect for mobile wallets
  • Automatic network switching
  • Real-time blockchain data updates

πŸ§ͺ Testing

Run All Tests

task test

Run Tests by Package

# Unit tests only
task test:unit

# Contract tests
task test:contracts

# E2E tests (requires dev stack running)
task test:e2e

# API tests
task test:api

# SDK tests
task test:sdk

# Core tests
task test:core

Watch Mode

task test:watch

Coverage

task test:coverage

Generate Test Documentation

task test:docs

This generates comprehensive test documentation in docs/TEST_RESULTS.md with:

  • Unit test results (TypeScript)
  • Smart contract test results (Solidity)
  • Coverage reports for both
  • Test file inventory

πŸ“Š Test Results

For detailed test results and coverage reports, see docs/TEST_RESULTS.md.

Current Test Summary:

  • Unit Tests: 9 tests passing (TypeScript)
  • Contract Tests: 35 tests passing (Solidity)
  • E2E Test Suites: 7 test suites (16+ test cases)
    • Contract integration tests
    • Purchase flow tests
    • Screenshot capture tests
    • Wallet connection tests
    • Accessibility tests
  • Total: 60+ tests

Coverage:

  • Unit Tests: 54.17% functions, 50.26% lines
  • Contract Tests: 56.44% lines, 50.57% statements
  • Core Contracts: 100% coverage for RefundableCrowdsale.sol and TimedCrowdsale.sol

E2E Test Requirements:

  • Dev stack running (task dev:up)
  • Contracts deployed (task contracts:deploy)
  • See TEST_RESULTS.md for details

Screenshot Tests: Generate screenshots for all crowdsale states (before opening, active, ended) with time manipulation:

task test:e2e:screenshots

Run task test:docs to regenerate the test documentation with the latest results.

πŸ“¦ Using the SDK

Install in your project:

bun add @bun-eth/sdk

Usage:

import { createClient } from "@bun-eth/sdk";

const client = createClient({
  baseUrl: "http://localhost:3001",
  timeout: 30000,
});

// Check health
const health = await client.health();

// Get wallet info
const wallet = await client.getWallet("0x...");

// Send transaction
const tx = await client.sendTransaction({
  to: "0x...",
  value: "1.0",
});

// Call contract
const result = await client.contractCall({
  contractAddress: "0x...",
  method: "retrieve",
  args: [],
});

πŸ”§ Configuration

Environment Variables

Copy .env.example to .env and configure:

# Port Configuration (consecutive ports for easy management)
WEB_PORT=3000
API_PORT=3001
ANVIL_PORT=3002

# API Configuration
PORT=3001
NODE_ENV=development

# Ethereum Node
ANVIL_NODE=http://localhost:3002
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

# Network Configuration
CHAIN_ID=31337

# Frontend (Optional)
NEXT_PUBLIC_WC_PROJECT_ID=  # WalletConnect Project ID

Foundry Networks

Edit packages/contracts/foundry.toml:

[rpc_endpoints]
localhost = "http://127.0.0.1:8545"
sepolia = "${SEPOLIA_RPC_URL}"

πŸš€ Quick Start Example

After running task dev:up and task contracts:deploy, use the new packages:

// In your component
import { useScaffoldReadContract, useScaffoldWriteContract } from "@bun-eth/hooks";
import { Address, Balance, FaucetButton, BurnerWalletInfo } from "@bun-eth/components";
import { useAccount } from "wagmi";

function MyDApp() {
  const { address } = useAccount();

  // Read contract state - auto-refreshes on new blocks
  const { data: value } = useScaffoldReadContract({
    contractName: "SimpleStorage",
    functionName: "retrieve",
    watch: true,
  });

  // Write to contract - includes notifications
  const { writeContractAsync, isMining } = useScaffoldWriteContract("SimpleStorage");

  const handleStore = async () => {
    await writeContractAsync("store", [42]);
  };

  return (
    <div>
      {/* Show burner wallet info if using burner */}
      <BurnerWalletInfo />

      {/* Display address with ENS */}
      <Address address={address} format="short" />

      {/* Balance with USD toggle */}
      <Balance address={address} usdMode />

      {/* Faucet for test ETH */}
      <FaucetButton />

      {/* Contract interaction */}
      <p>Stored Value: {value?.toString()}</p>
      <button onClick={handleStore} disabled={isMining}>
        {isMining ? "Mining..." : "Store 42"}
      </button>
    </div>
  );
}

πŸ“š Available Commands

Run task --list to see all available commands.

Essential Commands

# Setup - Complete local setup with tests
task setup

# Start - Quick start dev stack (install, compile, start services)
task start

# Development
task dev:up              # Start local development stack (Anvil + API + Web)
task dev:down            # Stop local development stack
task dev:logs            # View logs from all services

# Frontend
task web:dev             # Start Next.js dev server
task web:build           # Build Next.js for production
task web:start           # Start Next.js production server

# Contracts
task contracts:compile   # Compile smart contracts
task contracts:deploy    # Deploy to local network + generate types (πŸ”₯ hot reload)
task contracts:generate  # Generate TypeScript from deployed contracts
task contracts:test      # Run contract tests

# Testing
task test                # Run all tests
task test:core           # Run core utility tests only
task test:sdk            # Run SDK tests only
task test:contracts      # Run contract tests only

# Monitoring
task status              # Show development stack status with health checks
task check:health        # Check API health endpoint (with JSON output)

# Other
task clean               # Clean build artifacts

🚒 Deployment

Deploy to Production

  1. Set environment variables:
export NODE_ENV=production
export PRIVATE_KEY=your_private_key
export SEPOLIA_RPC_URL=your_rpc_url
  1. Deploy contracts:
task contracts:deploy:sepolia
  1. Build and deploy API:
docker build -f apps/api/Dockerfile -t bun-eth-api .
docker run -p 3001:3001 --env-file .env bun-eth-api

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -m 'feat: add my feature'
  4. Push to the branch: git push origin feature/my-feature
  5. Open a Pull Request

πŸ“š Documentation

General

Crowdsale

Packages

πŸŽ“ Learn More

πŸ“„ License

MIT License - see LICENSE file for details

πŸ™ Acknowledgments

  • Bun - The blazingly fast JavaScript runtime
  • Elysia - Fast and ergonomic TypeScript web framework
  • Foundry - Blazing fast Ethereum development toolkit
  • scaffold-eth-2 - Inspiration for features
  • wagmi + viem - Modern Ethereum libraries
  • RainbowKit - Beautiful wallet UX

πŸ“ž Support


Built with ⚑ by the Bun-Eth community

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors