Skip to content

Instantly share code, notes, and snippets.

@kowito
Created January 9, 2024 07:19
Show Gist options
  • Select an option

  • Save kowito/b0392c97a3071613ba90c0b32d9af6c2 to your computer and use it in GitHub Desktop.

Select an option

Save kowito/b0392c97a3071613ba90c0b32d9af6c2 to your computer and use it in GitHub Desktop.

Revisions

  1. kowito created this gist Jan 9, 2024.
    52 changes: 52 additions & 0 deletions init_hardhat.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/bin/bash

    # Get the project name from the first command line argument
    PROJECT_NAME=$1

    # Check if the project name was provided
    if [ -z "$PROJECT_NAME" ]; then
    echo "Error: No project name provided."
    echo "Usage: $0 <project_name>"
    exit 1
    fi

    # Create a new directory for your project and navigate into it
    mkdir "$PROJECT_NAME"
    cd "$PROJECT_NAME"

    # Initialize a new pnpm project (Press Enter to skip all prompts)
    pnpm init

    # Install Hardhat and additional specified packages as development dependencies
    pnpm add --save-dev hardhat @openzeppelin/contracts-upgradeable @nomiclabs/hardhat-ethers ethers

    # Initialize Git repository
    git init

    # Create directories for contracts, scripts, and tests
    mkdir contracts scripts test

    # Create a basic Hardhat project
    echo "module.exports = {};" > hardhat.config.js

    # Add Hardhat commands to package.json
    jq '.scripts = {
    "compile": "hardhat compile",
    "test": "hardhat test",
    "deploy": "hardhat run scripts/deploy.js",
    "node": "hardhat node"
    }' package.json > temp.json && mv temp.json package.json

    # Create a basic .gitignore file (optional)
    echo "node_modules
    dist
    .cache
    artifacts
    build
    coverage" > .gitignore

    # First Git commit with the project initialization message
    git add .
    git commit -m "Initial commit - Set up $PROJECT_NAME project"

    echo "Hardhat project initialized successfully in '$PROJECT_NAME' directory with basic structure and Git repository."