iTerm2 Web3 Wallet Extension

A browser extension that provides Web3 wallet functionality for iTerm2's Browser using Foundry Cast as the backend.

Architecture

This extension consists of:

  1. Browser Extension: Provides window.ethereum interface to web pages
  2. Cast HTTP Server: Modified Foundry Cast tool with JSON-RPC HTTP server
  3. Transaction UI: In-page confirmation modals for transaction approval

Components

Extension Files

  • manifest.json - Extension manifest (Manifest V3)
  • background.js - Service worker handling Cast communication
  • content-script.js - Injects window.ethereum provider into web pages
  • confirmation-modal.html - Transaction confirmation UI
  • confirmation-modal.css - Styling for confirmation modal

Background Script (background.js)

Handles:

  • Communication with Cast HTTP server on localhost:8545
  • Translation between Web3 JSON-RPC and Cast commands
  • Basic wallet operations (accounts, balance, transactions)

Content Script (content-script.js)

Provides:

  • EIP-1193 compliant window.ethereum provider
  • Legacy Web3 compatibility methods
  • Event handling for account/network changes

Confirmation Modal

  • Native in-page transaction confirmation
  • Shows transaction details, gas estimates, fees
  • User approval/rejection handling

Installation

Prerequisites

  1. Modified Cast Tool: Fork Foundry Cast with HTTP server support
  2. iTerm2 Browser: Latest version with WebExtensions support

Steps

  1. Install Modified Cast:

    # Build cast with HTTP server support
    git clone [cast-fork-repo]
    cd foundry
    cargo build --release --bin cast
    cp target/release/cast /usr/local/bin/cast-web3
  2. Start Cast HTTP Server:

    cast-web3 --http-server --port 8545
  3. Install Extension:

    • Copy extension folder to iTerm2 extensions directory
    • Enable in iTerm2 Browser settings

Usage

Starting the Wallet

  1. Start Cast HTTP server:

    cast-web3 --http-server
  2. Create or import wallet:

    cast-web3 wallet new  # Create new wallet
    # or
    cast-web3 wallet import --private-key 0x...  # Import existing
  3. Extension automatically connects to Cast server

Web3 dApp Integration

The extension provides a standard window.ethereum interface:

// Connect to wallet
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });

// Get balance
const balance = await ethereum.request({ 
  method: 'eth_getBalance',
  params: [accounts[0], 'latest'] 
});

// Send transaction
const txHash = await ethereum.request({
  method: 'eth_sendTransaction',
  params: [{
    from: accounts[0],
    to: '0x...',
    value: '0x1000000000000000000' // 1 ETH in wei
  }]
});

Supported Web3 Methods

Account Management

  • eth_requestAccounts - Connect wallet
  • eth_accounts - Get connected accounts

Network Information

  • eth_chainId - Get current chain ID
  • net_version - Get network version

Balance & Transactions

  • eth_getBalance - Get account balance
  • eth_sendTransaction - Send transaction
  • eth_call - Call contract method
  • eth_estimateGas - Estimate gas for transaction

Cast HTTP Server Modifications

The extension requires a modified version of Foundry Cast with HTTP server support:

New Cast Commands

  • cast --http-server - Start JSON-RPC HTTP server
  • cast wallet list - List available accounts (JSON)
  • Additional JSON output modes for all commands

HTTP Endpoints

  • POST / - JSON-RPC endpoint for all Cast operations
  • GET /health - Server health check

Command Mapping

  • eth_getBalancecast balance
  • eth_sendTransactioncast send
  • eth_callcast call
  • eth_chainIdcast chain-id

Development

File Structure

web3-wallet-extension/
├── manifest.json
├── background.js
├── content-script.js
├── confirmation-modal.html
├── confirmation-modal.css
└── README.md

Testing

  1. Load extension in iTerm2 Browser
  2. Navigate to a Web3 dApp (e.g., Uniswap)
  3. Connect wallet and test transactions

Debugging

  • Check browser console for Web3 provider logs
  • Monitor Cast server logs for RPC requests
  • Use iTerm2's extension debugging tools

Security Considerations

  • Extension runs in isolated context
  • Private keys managed by Cast (not extension)
  • Transaction confirmation required for all sends
  • No automatic transaction approvals

Future Enhancements

  • Hardware wallet support via Cast
  • Multi-network switching
  • Transaction history
  • Gas optimization
  • dApp permissions system