p00temkin / hhnode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HH NODE

Hardhat standalone node as docker image:

alt text

  • Resets to block 0 on restart
  • Chain ID 31337
  • RPC listens to localhost port 8545 connections
  • Generates 10 accounts with 100 ETH each
  • Automining enabled
  • Mnemonic for 10 prefunded accounts set to Hardhat default: "test test test test test test test test test test test junk"

Any changes to the above just edit hardhat.config.js before building the docker image. For port changes make sure to edit the port in Dockerfile as well.

Prerequisites

Docker 4.x+

Building the application

docker build -t hhnode .
docker run -d -p 8545:8545 hhnode

Expose over HTTPS using NGINX

If you want to wrap the RPC with HTTPS you can use NGINX. Create a config file under 'sites-enabled' with

upstream hhnode {
    server <your docker image IP>:8545 max_fails=30 fail_timeout=10s;
}

You can get the docker image IP-address by running "docker ps" to get the container id, then run

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id

Next setup your domain SSL certificate. Unless you are already setup with the ssl keys, a good guided option is to use https://letsencrypt.org/. Add the following section to your NGINX site config:

server {
    listen 443 ssl;
    server_name yourdomain;

    ssl_certificate /etc/letsencrypt/live/yourdomain/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain/privkey.pem;

    ...

Finally add a /rpc route to the RPC node in the server section:

    location /rpc {
        proxy_pass http://yourdomain;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header  Authorization $http_authorization;
        proxy_pass_header Authorization;
    }

Following these steps your Hardhat dev node should be available using "https://yourdomain/rpc". Add this as a new chain to Metamask and import the first prefunded account (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) and you will see 100 ETH balance.

alt text

Persist state

If you need to persist state the easiest way is to switch to Ganache 7.x and use the "--database.dbPath" option as shown below:

mkdir /var/ganache
docker run --detach \
	-v /var/ganache:/var/ganache \
	--publish 8545:8545 trufflesuite/ganache:v7.8.0 \
	--mnemonic "test test test test test test test test test test test junk" \
	--port 8545 \
	--accounts 10 \
	--chain.chainId 31337 \
	--chain.networkId 31337 \
	--miner.blockTime 1 \
	--wallet.defaultBalance 100 \
	--database.dbPath /var/ganache \
	--server.rpcEndpoint /rpc \
	-v

To reset the blockchain simply clear the folder /var/ganache.

Support/Donate

To support this project directly:

Ethereum/EVM: forestfish.x / 0x207d907768Df538F32f0F642a281416657692743
Algorand: forestfish.x / 3LW6KZ5WZ22KAK4KV2G73H4HL2XBD3PD3Z5ZOSKFWGRWZDB5DTDCXE6NYU

Or please consider donating to EFF: Electronic Frontier Foundation

or to Let's Encrypt: Let's Encrypt

About

License:Other


Languages

Language:JavaScript 69.1%Language:Dockerfile 20.1%Language:Shell 10.8%