DEV Community

Cover image for Running Your Own Ethereum Node with Geth
Noah Hein
Noah Hein

Posted on

Running Your Own Ethereum Node with Geth

Introduction

You may want to run your own Ethereum node for a multitude of reasons. If you do, you need to run an Ethereum client of some sort. There are plenty out there, but I settled on geth. An easier alternative, and one that has a nice GUI is ganache. I've also heard of hardhat.

I won't speak to the other tools I just mentioned, but I know geth can be used to deploy to the mainnet, and I wanted to futureproof my knowledge a bit. That means it doesn't have a few of the bells and whistles built-in like those other clients do.

So while we will be deploying a local node for testing a dapp; this could be used to mine real ether, transfer funds, and all the other blockchain goodies that you would expect.

This was a bit of a pain to do and I had to go scrounging through github issues to find something that worked for me. There wasn't any offical documentation that I could tell, so maybe that can be my first PR for geth. Or maybe you'll beat me to it after reading this!

Installation

I'm running Linux Mint and all commands will be listed as such

You will need to install Ethereum before anything else.

Setup the launchpad repoistory

sudo add-apt-repository -y ppa:ethereum/ethereum
Enter fullscreen mode Exit fullscreen mode

I recommend using the stable version:

sudo apt-get update
sudo apt-get install ethereum
Enter fullscreen mode Exit fullscreen mode

However, you can also use the development version like so:

sudo apt-get update
sudo apt-get install ethereum-unstable
Enter fullscreen mode Exit fullscreen mode

If you are on another OS you can check here.

Genesis Creation

Every blockchain has to start with a single block, and that is commonly referred to as the genesis block. It doesn't hold any transactions or any relevant data. It is merely a point for all the other blocks to be based off of.

Fun bit of history, you can see Ethereum's first block here.

I will use gethTutorial as my root folder for this example.

mkdir gethTutorial && cd gethTutorial
Enter fullscreen mode Exit fullscreen mode

You will want to create a folder inside of whatever root directory you're in called private.

mkdir -p private && cd private
Enter fullscreen mode Exit fullscreen mode

Now for your first geth command! You will run this inside the private directory

puppeth
Enter fullscreen mode Exit fullscreen mode

It will ask you for a network name. I used nheintestnet. You can use whatever you'd like.

It will ask you 6 questions, and I'll list the proper responses here:

  1. What would you like to do? 2. configure new genesis
  2. What would you like to do? 1. Create new genesis from scratch
  3. Which consensus engine to use? 1. Ethash - proof-of-work
  4. Which accounts should be pre-founded? Default option (hit enter)
  5. Should the precompile-addresses (0x1 .. 0xff) be pre-founded with 1 wei? Default option (hit enter)
  6. Specify your chain/netowrk ID if you want an explicit one: 4224

After that it will create a new series of questions:

  1. What would you like to do? 2. Manage existing genesis
    • 2. Export genesis configurations
    • which folder to save genesis spec into? Default option (hit enter)

It will continue to ask questions, but you can exit the interface with CRTL+C at this point.

you should have 4 .json files at this point. The one of note is the plain one that has no "-" suffix. In my case: nheintestnet.json

Populating the Blockchain

We now are going to create a place to store the blockchain data and the keystores. Keystores will hold your private keys that are associated with the accounts you make on this node.

geth --datadir ~/gethTutorial/private init nheintestnet.json
Enter fullscreen mode Exit fullscreen mode

You should now see chaindata and keystore folders.

Creating Accounts

Well we have a blockchain now, we just need to get some accounts to get things going.

geth --datadir . account new
Enter fullscreen mode Exit fullscreen mode

It will ask you to enter a password.

Do this process 2 more times so that you have 3 accounts in total.

You should be able to see all your accounts by running

geth --datadir . account list
Enter fullscreen mode Exit fullscreen mode

Starting Up the Blockchain

in your private folder create a file: startnode.sh

inside you will want to paste this:

geth --networkid 4225 --mine --miner.threads 1 --datadir "/home/noah/gethTutorial/private" --nodiscover --rpc --rpcport "8545" --port "30303" --rpccorsdomain "\*" --nat "any" --rpcapi eth,web3,personal,net --unlock 0 --password /home/noah/gethTutorial/private/password.sec --ipcpath "~/Library/Ethereum/geth.ipc" --allow-insecure-unlock
Enter fullscreen mode Exit fullscreen mode

You will want to change your locations of the --datadir flag, and the --password flag arguments. You can try your luck with the ~ in the file names. The documentation says it should work from what I read, but I couldn't get it to work. I reccomend just writing the /home/user/ in the arguments.

In the private folder, create a file: password.sec

In this file, put the password of the first account you created.

To make the script executable

chmod +x startnode.sh
Enter fullscreen mode Exit fullscreen mode

Then execute the script:

./startnode.sh
Enter fullscreen mode Exit fullscreen mode

This will create a running Ethereum server in the terminal you ran the script in. Leave this terminal running.

Connecting to the Blockchain

Create a new terminal, and let's try to connect to our new server.

geth attach http://127.0.0.1:8545

This should open up a Geth Javascript console. You can run JS code here.

for a quick test, try to list the accounts that we have connected to this blockchain.

eth.accounts
Enter fullscreen mode Exit fullscreen mode

It should spit back an array of the 3 account addresses we created.

You are now running a geth node on your computer, and also successfully connected to it! Congrats!

Top comments (5)

Collapse
 
block_gum profile image
Info Comment hidden by post author - thread only accessible via permalink
block gum

Disclaimer : I belong to the Blockgum it self, I am here introducing system that would be helpful for people using Geth and having hard time with lack features, ie Tracking deposits, processing withdrawals and Various stats monitoring.
*What is blockgum *
It is alternative for GETH + Moralis , as Its all in one solution for multiple chains .

Why blockgum
Does everything what moralis+ geth do , Run multiple chains , HDWallet and deposit tracking , No sync required , connect with multiple Public rpc http/wss sources.

Using one server and client you can install any EVM chain multiple chains same time.

Product Description:
Are you looking for a comprehensive and user-friendly solution to manage and track your digital assets on multiple EVM chains? Look no further than Blockgum! Our advanced HDWallet technology allows you to generate unlimited addresses with just one private key, and our derivation path is the same as Metamask. Plus, all geth features are already included.

Blockgum can track transfers and deposits of network coins or tokens on any EVM network, and it can run multiple networks at the same time. This means that you can use a single address per customer for all EVM networks, such as ETH, Matic, FTM, Avax, BNB or any other EVM network listed on chainlist.org. Our mobile client connects to the Blockgum server app and allows you to manage and track everything, with tools like emergency restart/shutdown, address generation and tracking, deposit tracking, withdrawal from main account or any user account, and more. Plus, the mobile app offers a secure login using QR, so you can scan the QR code from the server CLI.

On the server side, Blockgum offers unlimited address creation, support for any chain or multiple chains at the same time, no syncing required as it connects with Public RPC, super secure request to server are encrypted using JWT HS256, constant deposit tracking and deposit records in DB (MongoDB), withdrawals processing and records, deposit movement to main account, token monitoring and many more features.

Blockgum is ideal for a wide range of use cases, such as crypto exchanges supporting multiple chains, ICO/IDOs, wallet service providers, online stores accepting crypto as payment, and people using Ethereum Web3, Geth or Moralis. And with our REST APIs, you can connect to any server or client-side app.

We also provide complete Blockgum documentation, and our installation tool allows you to set up Blockgum in just a few steps, as quick as an hour max.

With over 378 mainnet and 300 testnets supported by Blockgum, including popular chains like ETH, Matic, BNB, Avax, FTM, MOVR, CRO, HT, TOMO, and KLAY, you can easily support any EVM network by simply adding its RPC (HTTP/WSS) in chains.json. And with our commitment to privacy, Blockgum is an independent server application that does not share any information with anyone, including us. All we know is the MD5 of the Extended master public key.

For more information, check out the video at to see how easy it is to install Blockgum on your server. Blockgum Server youtube.com/watch?v=6qBnSG80rVQ Blockgum Mobile youtube.com/watch?v=jaL4HY-MASw

Product Page EVM Wallet
Thank you

Collapse
 
lepinekong profile image
lepinekong

What disk space will it take ?

Collapse
 
nheindev profile image
Noah Hein

It depends on whether or not you're syncing to the mainnet. If you're running a private node as I outline in the tutorial it doesn't take much space at all.

I didn't check; but it is a negligible amount memory.

If you're running an up-to-date Mainnet Ethereum node is around 830 gigs according to etherscan. (etherscan.io/chartsync/chaindefault)

While an archive node on Ethereum sits at around 7.5 terabytes: etherscan.io/chartsync/chainarchive

Collapse
 
swizzard profile image
sam

Cryptocurrencies are destroying the planet.

Collapse
 
speqtovijay profile image
Vijay Thakur

how to start blockchain faucet provided in geth

Some comments have been hidden by the post's author - find out more