Tutorial: Play with Geth (Go Ethereum) (2024)

Yongchang He

Posted on

Tutorial: Play with Geth (Go Ethereum) (3) Tutorial: Play with Geth (Go Ethereum) (4) Tutorial: Play with Geth (Go Ethereum) (5) Tutorial: Play with Geth (Go Ethereum) (6) Tutorial: Play with Geth (Go Ethereum) (7)

#tutorial #blockchain #beginners #ethereum

Interact with a command-line tool for running a private Ethereum blockchain network (MacOS)

This tutorial is meant for those with a basic knowledge of Ethereum and smart contracts, who have some knowledge of HTML and JavaScript, but who are new to dApps.
The purpose of building this blog is to write down the detailed operation history and my memo for learning the dApps.
If you are also interested and want to get hands dirty, just follow these steps below and have fun!~

Prerequisites

  • MacOS
  • CLI with Homebrew installed
  • Coding IDE

Intro & Review

In this tutorial we will be covering:

  1. Install Geth
  2. Run Geth
  3. Create new accounts
  4. Create genesis block
  5. Deploy private blockchain
  6. Mining Ethereum blocks
  7. Sending Tokens

What is Geth?

Geth(Go Ethereum) is a command-line interface for running Ethereum nodes implemented in Go Language. Using Geth you can join the Ethereum network, transfer ether between accounts or even mine ethers.

Getting started

Install Geth

We should first install Geth using the following CLI command:

brew tap ethereum/ethereumbrew install ethereum

Then we can navigate to our favourite directory, create a folder with your favourite name (e.g. named my-private-blockchain)and navigate into the folder using the following command:

mkdir private-blockchain-gethcd private-blockchain-geth

Tutorial: Play with Geth (Go Ethereum) (8)

Run Geth

We can then run the following command to see if Geth has been installed successfully:

geth

If your CLI gets information like mine, congrats! You are on the track now. Geth is attempting to download the entire blockchain data into your PC, and the data can take up a ton of disk space. Just Control C to stop the command.

Tutorial: Play with Geth (Go Ethereum) (9)

If you are very interested in what has happened just now, you can open a new CLI and navigate to the following directory to see the history logs:

cd Library/Ethereum/geth/ls

Tutorial: Play with Geth (Go Ethereum) (10)

Create new accounts

Let's run the following command to create the first account on our private blockchain:

geth account new

This command will then prompt us to enter a password to ensure security. After entering the password two times, our account 0 has been created.

Tutorial: Play with Geth (Go Ethereum) (11)

Run geth account new again, to create our Account 1:

Tutorial: Play with Geth (Go Ethereum) (12)

Create genesis block

We need to create a genesis block - the first block of the blockchain - to initialize our blockchain network.

Next let's open the folder /private-blockchain-geth using our favourite IDE (Mine is VSCode, and currently there is no file in this directory), create a file named genesis-block.json, copy and paste the following code to this file:

{ "config": { "chainId": 15, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "ethash": {} }, "difficulty": "1", "gasLimit": "8000000", "alloc": {} }

Tutorial: Play with Geth (Go Ethereum) (13)

The next step is to initialize the genesis block using this command:

geth --datadir . init genesis-block.json

Tutorial: Play with Geth (Go Ethereum) (14)

Deploy private blockchain

The log "Successfully wrote genesis state" indicates that we have created our first block correctly. Now we can deploy our blockchain using the following command:

geth --allow-insecure-unlock --datadir . --keystore ~/Library/ethereum/keystore --networkid 4568 --http --http.addr '0.0.0.0' --http.corsdomain "*" --http.port 8502 --http.api 'personal,eth,net,web3,txpool,miner' --mine --miner.etherbase=YOUR_ACCOUNT_0_ADDRESS

Note: Replace YOUR_ACCOUNT_0_ADDRESS with your account 0 Public address of the key

Tutorial: Play with Geth (Go Ethereum) (15)

Tutorial: Play with Geth (Go Ethereum) (16)

We have kicked off an interactive session that keeps printing new INFO of our blockchain. Leave it running and let's start a new CLI, navigate to the same directory /private-blockchain-geth and initialize Geth JavaScript console by running the following command:

geth attach geth.ipc

Tutorial: Play with Geth (Go Ethereum) (17)

Mining Ethereum blocks

To begin mining our blockchain, we can run:

Let's allow it to run for a while, and then stop the mining by typing:

miner.stop()

Now We have rewarded some tokens for mining new blocks. We can verify this by running the following command:

eth.getBalance(eth.accounts[0])

Tutorial: Play with Geth (Go Ethereum) (18)

Sending Tokens

Run the following command to finish the authentication process of account 0 before sending tokens:

personal.unlockAccount(eth.accounts[0])

Input the password we have set to unlock account 0:
Tutorial: Play with Geth (Go Ethereum) (19)

Now let's transfer tokens from account 0 to account 1 by running this command:

eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: 500000})

Value here is in Wei (Where 1 ETH equals 1 x 10 ^ 18 Wei)

We should get a green transaction hash if the transaction has been done correctly.
Tutorial: Play with Geth (Go Ethereum) (20)

Since we had stopped the mining process before we were creating the transaction, this transaction is added to the memory pool rather than being added to the blockchain. At this point, account 1 cannot receive the transferred token if we run:

eth.getBalance(eth.accounts[1])

Tutorial: Play with Geth (Go Ethereum) (21)

Let's start the mining process again for a while:
Tutorial: Play with Geth (Go Ethereum) (22)

And run the following again:

eth.getBalance(eth.accounts[1])

Finally transferred tokens have been received by account 1:

Tutorial: Play with Geth (Go Ethereum) (23)

Pretty COOL!

References
https://dev.to/heydamali/a-guide-to-private-ethereum-mining-with-geth-go-ethereum-13ol

https://geth.ethereum.org/docs/interface/managing-your-accounts

https://cointelegraph.com/news/high-severity-ethereum-geth-nodes-crash-eth-hashrate-drops-etc-remains-safe

https://trufflesuite.com/tutorial/index.html

Top comments (6)

Subscribe

Jorge Ramires

Jorge Ramires

  • Education

    Loyola University of Chicago

  • Work

    Software Engineer

  • Joined

Jun 14 '22

  • Copy link

Thanks for the tutorial! Had a lot of fun! Do you have more projects like this to practice? Would love to try them

Yongchang He

Yongchang He

An IoT and blockChain developer;interested in Cloud Computing;love coding...

  • Email

  • Location

    Saskatoon, Saskatchewan

  • Education

    Computer Science, master's, University of Saskatchewan

  • Joined

Jun 14 '22

  • Copy link

Hello there,

Glad you love it!

I do have published several tutorials related with playing web3, blockchain, smart contract side of things. Such as build your own multi-node chain, play with truffle and ganacheUI, Solidity smart contract practice and so on.

Contact me if more resources or tutorials or answers needed.

Cheers and have fun!

Jorge Ramires

Jorge Ramires

  • Education

    Loyola University of Chicago

  • Work

    Software Engineer

  • Joined

Jun 14 '22

  • Copy link

Do you have more tutorials or projects with Geth specifically? Something to practice and learn. Thank you very much!

Yongchang He

Yongchang He

An IoT and blockChain developer;interested in Cloud Computing;love coding...

  • Email

  • Location

    Saskatoon, Saskatchewan

  • Education

    Computer Science, master's, University of Saskatchewan

  • Joined

Jun 14 '22

  • Copy link

This one is with Geth. Using this one you may want to try and practice with building your own multiple nodes on different PCs that connected to your local chain, and can interact with each other and the smart contract that deployed on the chain.
You can find docs and more funs on official Geth.

Cheers!

Sakshi

Sakshi

Loves programming! Web Dev Enthusiast. Getting my hands dirty with ANGULAR.Available for hire

  • Location

    India

  • Education

    Undergraduate | Geek

  • Joined

Apr 4 '22

  • Copy link

Thanks for the wonderful tutorial!

Yongchang He

Yongchang He

An IoT and blockChain developer;interested in Cloud Computing;love coding...

  • Email

  • Location

    Saskatoon, Saskatchewan

  • Education

    Computer Science, master's, University of Saskatchewan

  • Joined

Apr 4 '22

  • Copy link

Great to hear that :). Thank you!

For further actions, you may consider blocking this person and/or reporting abuse

Tutorial: Play with Geth (Go Ethereum) (2024)

FAQs

How to interact with geth? ›

Interacting with Geth Using Dapps

Here's how it works: Using Geth Directly: Run a Node: Users run a Geth node to fully participate in the Ethereum network. JSON-RPC API: dApps interact with Geth through the JSON-RPC API, which allows programmatic access to the node's functionalities.

How to build an Ethereum private blockchain using geth? ›

Below is the step-by-step guide to setting up a private Ethereum network.
  1. Step 1: Install Geth on Your System. ...
  2. Step 2: Create a Folder For Private Ethereum. ...
  3. Step 3: Create a Genesis Block. ...
  4. Step 4: Execute genesis file. ...
  5. Step 5: Initialize the private network. ...
  6. Step 6: Create an Externally owned account(EOA)
Apr 24, 2023

How to mine using Go Ethereum? ›

In order to earn ether through you need to have a coinbase (or etherbase) address set. This etherbase defaults to your primary account. If you got no etherbase address set, then geth --mine will not start up. Note that your coinbase does not need to be an address of a local account, just an existing one.

How to start geth console? ›

To start Geth, run the Geth executable file passing argument that define the data directory (where Geth should save blockchain data), signer (points Geth to Clef), the network ID and the sync mode. For this tutorial, snap sync is recommended (see here for reasons why).

How do you get peace with Geth? ›

The most common and reliable guide I have found for brokering peace between the geth and the quarian is the following: In order to achieve peace between the two races, you need to get 5 to 7 points. These points are based on your ME2 and ME3 decisions. If you have 4 points or below, you cannot achieve peace.

What is the max peer count for Geth? ›

The default peer limit is 50 for Geth and this is eating up bandwidth at an insane rate of 30+GB per day.

Is it possible to mine 1 Ethereum a day? ›

Unlike Bitcoin, there is no limit to the amount of Ethereum that can be generated. Each day around 13,500 Ether are mined.

How long does it take to mine 1 Ethereum on a laptop? ›

The time it takes to mine 1 Ethereum can vary significantly based on several factors, including the hash rate of your mining rig, the current mining difficulty, and luck. However, with a powerful mining rig and favorable conditions, it typically takes several days (up to 60 days) to several weeks to mine 1 Ethereum.

How profitable is ETH mining? ›

If the price goes up, you will make more money, but if it goes down, you will make less. In general, you can expect to make between $0.10 and $10 per day mining Ethereum, depending on all of the factors mentioned above.

How to fork Ethereum and become a private chain? ›

Steps to Fork Ethereum and Create Your Own Private Chain
  1. Set Up Your Development Environment: Before forking Ethereum, you need to set up your development environment. ...
  2. Clone the Ethereum Repository: The next step is to clone the Ethereum repository from GitHub.
Jul 7, 2024

What is the default port of Geth? ›

The default port ( 8545 ) can be change as well as the listing address ( localhost ). The JSON RPC can also be started from the geth console using the admin.

How to setup geth node? ›

Setup
  1. Step 1: Install the geth client. ...
  2. Step 2: Create genesis.json. ...
  3. Step 3: Initiate the private blockchain. ...
  4. Step 4: Add the first node to the private blockchain. ...
  5. Step 5: Add one more node to the private blockchain. ...
  6. Step 6: Connect node2 with node1 as peer. ...
  7. Step 7: Do a transaction between two accounts.
May 1, 2023

How to run node using geth? ›

Use geth attach

The console subcommand starts the Geth node and opens the console, while the attach subcommand attaches an already-running Geth instance to the console. Run the attach subcommand and connect to the IPC socket, or, if enabled, to the RPC or WebSocket API endpoints: IPC socket. RPC API endpoint.

How do I get the sync status of Geth? ›

You can check your Geth execution node's sync status by running geth attach (IPC) or geth attach http://localhost:8545 (HTTP) from a separate terminal. Then type eth. syncing . A sync status of false indicates that your node is fully synced.

How to get geth? ›

Where & How to Buy Goerli ETH (GETH) Guide
  1. Download a Trust Wallet Wallet. ...
  2. Set up your Trust Wallet. ...
  3. Buy ETH as Your Base Currency. ...
  4. Send ETH From Binance to Your Crypto Wallet. ...
  5. Choose a Decentralized Exchange (DEX) ...
  6. Connect Your Wallet. ...
  7. Trade Your ETH With the Coin You Want to Get.

How do I import my Geth account into MetaMask? ›

Import Accounts in metamask: Import using json file. Click on 'Import Account' and select Type as 'JSON File' and select the keystore file and pass the password for the keystore file. And click on Import, it will import the account.

Top Articles
All About Crypto Loans
Bloomberg Commodity Prices and Bloomberg Commodity Futures Prices - Barchart.com
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Selly Medaline
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 5783

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.