Skip to content

ernanibmurtinho/alchemy-bootcamp-week3

Repository files navigation

⛓️ Ethereum Block Explorer

Next.js 16 React 19 Tailwind CSS 4 Alchemy SDK TypeScript License: MIT

A comprehensive Ethereum blockchain explorer built for Week 3 of the Alchemy Ethereum Bootcamp. Explore blocks, transactions, accounts, NFTs, and send ETH programmatically - easier than MetaMask! πŸš€πŸ”πŸ’Έ

🌟 Overview

This block explorer provides a complete set of tools to interact with Ethereum:

πŸ—οΈ Core Features

  1. πŸ” Block Explorer - Browse latest blocks and their transactions
  2. πŸ‘€ Account Lookup - Check balances and transaction history
  3. 🎨 NFT Metadata - Fetch NFT details by contract address and token ID
  4. πŸ“Š Transaction Status - Track transaction confirmations and receipts
  5. πŸ’Έ Transfer History - View asset transfers by wallet address
  6. πŸš€ Testnet Playground - Send ETH programmatically (testnet supported)

⚑ Why Use Code Over MetaMask?

  • βœ… No popups - Transactions execute instantly
  • βœ… Batch operations - Send multiple transactions with ease
  • βœ… Automation - Integrate into scripts and workflows
  • βœ… Testing - Perfect for testnet experimentation
  • βœ… Reliability - No browser extension dependencies

🧩 Architecture & Technology Stack

Frontend

  • Next.js 16 ⚑: React framework with App Router
  • React 19 βš›οΈ: Latest React with concurrent features
  • Tailwind CSS 4 πŸ’„: Utility-first CSS framework
  • shadcn/ui 🎨: Accessible component library
  • TypeScript 5.7 πŸ“: Type-safe development

Blockchain Integration

  • Alchemy SDK 3.x βš—οΈ: Enhanced Ethereum API access
  • ethers.js 6.x πŸ”—: Ethereum utilities and wallet management

Development Tools

  • pnpm πŸ“¦: Fast, disk space efficient package manager
  • ESLint πŸ”: Code quality enforcement
  • PostCSS 🎨: CSS processing with Tailwind

πŸ“Έ Quick Demo

Ethereum Block Explorer Demo

Home page featuring all the explorer tools: Blocks, Accounts, NFT Lookup, Transaction Status, Transfers, and Testnet Playground.

πŸ› οΈ Setup

Prerequisites

  • 🟒 Node.js 18.0 or later
  • πŸ“¦ pnpm (recommended) or npm
  • πŸ”‘ Alchemy Account (free tier works!)

Installation

  1. πŸ“₯ Clone this repository:

    git clone [email protected]:ernanibmurtinho/alchemy-bootcamp-week3.git
    cd alchemy-bootcamp-week3
  2. πŸš€ Install dependencies:

    pnpm install
  3. πŸ” Set up environment variables:

    Create a .env.local file:

    # Alchemy API Key (required - server-side only)
    ALCHEMY_API_KEY=your_alchemy_api_key_here
    
    # Network (optional, defaults to mainnet)
    # Options: mainnet, sepolia, goerli
    ALCHEMY_NETWORK=mainnet

    ⚠️ Important: The API key is only used server-side in API routes for security.

  4. ▢️ Start the development server:

    pnpm dev
  5. 🌐 Open your browser at http://localhost:3000

πŸš€ Usage

Pages Overview

Page Route Description
🏠 Home / Feature cards linking to all sections
πŸ” Blocks /blocks Browse latest blocks with transaction counts
πŸ‘€ Accounts /accounts Look up balances and transaction history
🎨 NFT Lookup /nft-lookup Fetch NFT metadata by contract and token ID
πŸ“Š Tx Status /transaction-status Check transaction status by hash
πŸ’Έ Transfers /transfers View asset transfers for any wallet
πŸš€ Playground /playground Send testnet ETH programmatically

Page Details

Block Explorer πŸ”

  • View latest block numbers and details
  • Browse transactions within blocks
  • Navigate between blocks
  • See gas usage and timestamps

Accounts Page πŸ‘€

  • Enter any Ethereum address
  • View ETH balance in real-time
  • See transaction history
  • Detect if address is a contract

NFT Lookup 🎨

  • Enter contract address and token ID
  • Fetch complete NFT metadata
  • View token name, description, and attributes
  • Display token image when available

Transaction Status πŸ“Š

  • Enter transaction hash
  • View confirmation status
  • See gas used and transaction details
  • Track pending transactions

Transfer History πŸ’Έ

  • Enter wallet address
  • View all transfers received
  • Filter by token type (ERC-20, ERC-721, ERC-1155)
  • See timestamps and values

🌐 Using Testnet

Why Testnet?

Testnets let you experiment without spending real ETH. Perfect for learning!

Testnet Setup

  1. πŸ”‘ Create a testnet API key in Alchemy Dashboard

  2. πŸ”„ Update .env.local:

    ALCHEMY_API_KEY=your_testnet_api_key
    ALCHEMY_NETWORK=sepolia
  3. πŸ”„ Restart the dev server

Getting Testnet ETH

Network Faucets
Sepolia Alchemy Faucet β€’ PoW Faucet
Holesky Holesky Faucet

πŸ’Έ Sending ETH Transactions

Example: Send ETH Programmatically

The playground page (/playground) lets you send testnet ETH. Here's how it works under the hood:

import { Alchemy, Network } from 'alchemy-sdk';
import { Wallet, parseEther } from 'ethers';

const settings = {
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_SEPOLIA, // Use testnet!
  connectionInfoOverrides: {
    skipFetchSetup: true, // Required for server-side
  },
};

const alchemy = new Alchemy(settings);

export async function sendETH(toAddress: string, amountInETH: number, privateKey: string) {
  try {
    const provider = await alchemy.config.getProvider();
    const wallet = new Wallet(privateKey, provider);
    
    const tx = await wallet.sendTransaction({
      to: toAddress,
      value: parseEther(amountInETH.toString()),
    });
    
    console.log('Transaction sent:', tx.hash);
    const receipt = await tx.wait();
    
    return { success: true, hash: tx.hash, block: receipt?.blockNumber };
  } catch (error) {
    return { success: false, error: (error as Error).message };
  }
}

Usage

const result = await sendETH(
  '0xRECIPIENT_ADDRESS_HERE',  // Recipient address
  0.1,                          // Amount in ETH
  'your_private_key'            // ⚠️ Never commit this!
);

πŸ“ Project Structure

alchemy-bootcamp-week3/
β”œβ”€β”€ app/                        # Next.js App Router pages
β”‚   β”œβ”€β”€ page.tsx               # Home page with feature cards
β”‚   β”œβ”€β”€ layout.tsx             # Root layout with navbar
β”‚   β”œβ”€β”€ globals.css            # Global styles and theme
β”‚   β”œβ”€β”€ blocks/
β”‚   β”‚   └── page.tsx           # Block explorer page
β”‚   β”œβ”€β”€ accounts/
β”‚   β”‚   └── page.tsx           # Account lookup page
β”‚   β”œβ”€β”€ nft-lookup/
β”‚   β”‚   └── page.tsx           # NFT metadata page
β”‚   β”œβ”€β”€ transaction-status/
β”‚   β”‚   └── page.tsx           # Transaction status page
β”‚   β”œβ”€β”€ transfers/
β”‚   β”‚   └── page.tsx           # Transfer history page
β”‚   β”œβ”€β”€ playground/
β”‚   β”‚   └── page.tsx           # Testnet playground page
β”‚   └── api/                   # API routes (server-side)
β”‚       β”œβ”€β”€ blocks/
β”‚       β”‚   └── with-transactions/route.ts
β”‚       β”œβ”€β”€ transaction/route.ts
β”‚       β”œβ”€β”€ transfers/route.ts
β”‚       β”œβ”€β”€ account/
β”‚       β”‚   β”œβ”€β”€ info/route.ts
β”‚       β”‚   └── transactions/route.ts
β”‚       └── nft/
β”‚           └── metadata/route.ts
β”œβ”€β”€ components/                 # React components
β”‚   β”œβ”€β”€ navbar.tsx             # Navigation component
β”‚   β”œβ”€β”€ send-eth-form.tsx      # Send ETH form
β”‚   └── ui/                    # shadcn/ui components
β”œβ”€β”€ lib/                       # Utilities
β”‚   β”œβ”€β”€ alchemy.ts             # Alchemy SDK setup (server-only)
β”‚   β”œβ”€β”€ format-utils.ts        # Formatting helpers
β”‚   └── utils.ts               # General utilities
β”œβ”€β”€ .env.local                 # Environment variables (create this)
β”œβ”€β”€ package.json               # Dependencies
└── README.md                  # This file

πŸ”Œ API Routes

All Alchemy SDK calls are made server-side through API routes to keep the API key secure:

Endpoint Method Description
/api/blocks/with-transactions GET Fetch latest blocks with transaction data
/api/transaction GET Get transaction details by hash
/api/transfers GET Fetch asset transfers for an address
/api/account/info GET Get account balance and transaction count
/api/account/transactions GET Get recent transactions for an account
/api/nft/metadata GET Fetch NFT metadata

πŸ“– Alchemy SDK vs ethers.js

The Alchemy SDK wraps ethers.js with enhanced functionality:

Operation ethers.js Alchemy SDK
Get block number provider.getBlockNumber() alchemy.core.getBlockNumber()
Get block provider.getBlock(n) alchemy.core.getBlock(n)
Get balance provider.getBalance(addr) alchemy.core.getBalance(addr)
NFT metadata ❌ Not available alchemy.nft.getNftMetadata()
Asset transfers ❌ Not available alchemy.core.getAssetTransfers()

Need full ethers.js access?

const ethersProvider = await alchemy.config.getProvider();

πŸ”— Resources

Documentation

Block Explorers

🚨 Security Best Practices

Rule Description
πŸ” Never commit private keys Use .env.local and add to .gitignore
πŸ§ͺ Use testnet first Always test transactions on testnet
πŸ”’ Server-side API keys API keys are only used in API routes
βœ… Validate addresses Check address format before transactions
πŸ’° Check balances Verify sufficient funds before sending
⚠️ Handle errors Implement proper error handling

πŸ§ͺ Development

Available Scripts

# Start development server
pnpm dev

# Build for production
pnpm build

# Start production server
pnpm start

# Run linting
pnpm lint

Testing Your Setup

# Verify Alchemy connection
curl -X POST https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Server-Side Configuration Note

When using Alchemy SDK in Next.js API routes, add this configuration to avoid fetch issues:

const settings = {
  apiKey: process.env.ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
  connectionInfoOverrides: {
    skipFetchSetup: true, // Required for server-side environments
  },
};

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes
  4. Commit: git commit -m 'Add new feature'
  5. Push: git push origin feature/new-feature
  6. Submit a pull request

πŸ‘€ Author

Ernani Britto

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ by Ernani Britto for the Alchemy Ethereum Bootcamp Week 3

About

This repository is a quickstart, and the idea is help those who just started learning.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •