Guide: Self Hosting an Ethereum Node with Docker
Success in trading hinges on the swift reduction of time between decisions; speed optimizes opportunities and defines the winner.
Ethereum is a global, decentralized platform that operates using blockchain technology. It is popular among investors for its native cryptocurrency, ether (ETH), and favored by developers for its application in developing blockchain and decentralized finance applications. Ethereum is accessible to everyone and engineered to be scalable, programmable, secure, and decentralized, allowing for the creation of secure digital technologies.
Hosting an Ethereum Node
Hosting an Ethereum node not only supports the network's decentralization but also enhances privacy and reduces the time for RPC (Remote Procedure Call) calls. For those engaged in automated trading, operating a self-hosted Ethereum node can be crucial, as it decreases the latency between RPC calls, which is essential for the effectiveness of trading bots.
Recommended Hardware Requirements:
A fast CPU with 4+ cores
16 GB+ of RAM
A fast SSD drive with at least 2 TB of space
Configuring the Environment
The ideal environment for hosting an Ethereum node would be on a persistent Linux OS such as Ubuntu or Debian. In the guide we will be assuming Ubuntu 22.04, Docker, with docker-compose, allows for the containerization of the instances for Go-Ethereum (aka. Geth) with Prsym.
Install Docker
The installation documents for Docker are comprehensive and can be accessed here.
Install Docker Compose (docker-compose)
The installation documents for docker-compose are comprehensive and can be accessed here.
Initializing Geth and Prysm via Docker
Initializing Geth and Prysm is simple with the following steps:
Create a directory for the Geth and Prysm data. The guide assumes the data can be stored in your home directory
mkdir geth
cd geth
Create the docker-compose.yml file which will contain the Docker payload
nano docker-compose.yml
In the docker-compose.yml file, paste the following payload:
version: "3.8"
services:
geth:
image: ethereum/client-go:stable
container_name: geth
restart: unless-stopped
ports:
- 30303:30303
- 30303:30303/udp
- 8545:8545
- 8546:8546
- 8551:8551
volumes:
- ./data/geth:/root/.ethereum
stop_signal: SIGINT
stop_grace_period: 1m
healthcheck:
test: [ "CMD-SHELL", "geth attach --exec eth.blockNumber" ]
interval: 10s
timeout: 5s
retries: 5
command:
- --rpc.allow-unprotected-txs
- --snapshot=true
- --gcmode=full
- --http
- --http.api=eth,net,web3,engine,admin
- --http.addr=0.0.0.0
- --http.vhosts=*
- --http.corsdomain=*
- --ws
- --ws.origins=*
- --ws.addr=0.0.0.0
- --ws.api=eth,net,web3
- --graphql
- --graphql.corsdomain=*
- --graphql.vhosts=*
- --authrpc.addr=0.0.0.0
- --authrpc.vhosts=*
- --authrpc.jwtsecret=/root/.ethereum/jwt.hex
- --authrpc.port=8551
- --cache=42738 # should be 34% of RAM
prysm:
image: gcr.io/prysmaticlabs/prysm/beacon-chain
container_name: prysm
restart: unless-stopped
stop_grace_period: 1m
volumes:
- ./data/prysm:/data
- ./data/geth/jwt.hex:/geth/jwt.hex
depends_on:
geth:
condition: service_healthy
ports:
- 4000:4000
- 3500:3500
command:
- --accept-terms-of-use
- --datadir=/data
- --disable-monitoring
- --rpc-host=0.0.0.0
- --execution-endpoint=http://99.97.0.1:8551
- --jwt-secret=/geth/jwt.hex
- --rpc-host=0.0.0.0
- --rpc-port=4000
- --grpc-gateway-corsdomain=*
- --grpc-gateway-host=0.0.0.0
- --grpc-gateway-port=3500
- --min-sync-peers=7
- --historical-slasher-node=true
- --checkpoint-sync-url=https://sync.invis.tools
- --genesis-beacon-api-url=https://sync.invis.tools
- --suggested-fee-recipient=0xE87C5490687A4e545aA4eaF73a5aFE45aB9f8262
networks:
default:
ipam:
driver: default
config:
- subnet: 99.97.0.0/16
Start the Docker container daemons so they will be running persistently
docker-compose up -d
The log of the Docker containers may be followed with the following:
# follow the logs of the Geth container
docker logs -f geth
# follow the logs of the Prysm container
docker logs -f beacon
Profit! Well, almost. Unfortunately, it’ll take a few days for the Geth node to sync with the Ethereum mainnet but you’ll soon have everything you need to do unlimited and fast RPC calls to an Ethereum node.
Conclusion
Self-hosting an Ethereum node is crucial for the success of automated trading and arbitrage, including automated liquidations. By operating your own Ethereum node, you can significantly decrease the latency between call and response times, facilitating the development of automated tools without the worry of missing transactions or exceeding the permitted number of calls. For those using the guide to develop an automated trading bot, self-hosting an Ethereum node is crucial for success, as latency in RPC calls could result in missed opportunities.
Happy programming!