Skip to content

Instantly share code, notes, and snippets.

@obdura
Last active December 28, 2024 23:50
Show Gist options
  • Select an option

  • Save obdura/a9f468167ce1b688d3e1d3f297dbf8d6 to your computer and use it in GitHub Desktop.

Select an option

Save obdura/a9f468167ce1b688d3e1d3f297dbf8d6 to your computer and use it in GitHub Desktop.
Setup a hardhat node on a container using docker compose
# Set the seed mnemonic phrase
SEED_MNEMONIC_CODE="test test test test test test test test test test test lizard"
# Set the wallet key identifier
HD_WALLET_KEY_IDENTIFIER="m/44'/60'/0'/0"
# Set the amount of default accounts
ACCOUNTS_COUNT=5
services:
hardhat-node:
image: node:22-alpine
working_dir: /hardhat-node
command: >
/bin/sh -c 'npm install --save-dev hardhat;
npx hardhat vars setup;
npx hardhat node --port 8545'
ports:
- "8545:8545"
volumes:
- type: bind
source: ./hardhat.config.js
target: /hardhat-node/hardhat.config.js
env_file:
- path: ".env"
// Use the .env environmental variables, or use the defaults
const SEED_MNEMONIC_CODE = process.env.SEED_MNEMONIC_CODE ? process.env.SEED_MNEMONIC_CODE : "test test test test test test test test test test test junk";
const HD_WALLET_KEY_IDENTIFIER = process.env.HD_WALLET_KEY_IDENTIFIER ? process.env.HD_WALLET_KEY_IDENTIFIER : "m/44'/60'/0'/0";
const ACCOUNTS_COUNT = process.env.ACCOUNTS_COUNT ? parseInt(process.env.ACCOUNTS_COUNT) : 20;
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.27",
networks: {
hardhat: {
chainId: 31337,
accounts: {
mnemonic: SEED_MNEMONIC_CODE,
path: HD_WALLET_KEY_IDENTIFIER,
count: ACCOUNTS_COUNT,
},
},
},
};
#!/bin/zsh
SCRIPT_PATH="${0:a:h}"
echo "Running hardhat node on Docker container."
docker compose -f $SCRIPT_PATH/docker-compose.yml up --detach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment