-
-
Save obdura/a9f468167ce1b688d3e1d3f297dbf8d6 to your computer and use it in GitHub Desktop.
Setup a hardhat node on a container using docker compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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, | |
| }, | |
| }, | |
| }, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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