getting started with ethereum (2024)

Goals

  1. Create a private Ethereum blockchain network with 2 nodes
  2. Create a simple SmartContract with the Solidity IDE
  3. Start and observe that the mining process is working on both nodes

Getting started

Install Geth. Geth is the Go language Ethereum CLI client and is used to interact with Ethereum networks.

INSTALL GETH

Create a private Ethereum blockchain network

For development purposes, you can set up a "private" Ethereum blockchain that is separate from the main Ethereum blockchain. A private network is useful for testing out distributed applications without needing to use real ether. This tutorial assumes you are on an unix computer.

  1. Create an Ethereum directory where you will store your local blockchain

    mkdir ethereum

  2. Create an environment variable called ‘ethereum_home’ in your .bash_profile file in your home directory. ‘Ethereum_home’ should point to the directory where you are storing your ethereum dapp folders:

    echo 'export ethereum_home=/Path_to_folder/ethereum' >> ~/.bash_profile

  3. In your ethereum directory create a new file genesis.json, paste the below code and save. A genesis block is required for a private network. This defines the properties of your blockchain. The difficulty property determines how long it will take for miners to mine blocks. I recommend setting it to something low

    {

    "config": {

    "chainId": 1234,

    "homesteadBlock": 0,

    "eip155Block": 0,

    "eip158Block": 0

    },

    "difficulty": "2",

    "gasLimit": "0x8000000",

    "alloc": {}

    }

  4. Initialize a new blockchain network with the genesis block and create the first node. Create a directory in your ‘ethereum_home’ home path for your first node (e.g. ‘chain1’). In a console window type the following:

    geth --datadir "$ethereum_home/chain1" init "$ethereum_home/genesis.json"

  5. Start your node. Note that each node runs on its own port so if you run multiple nodes on your development machine they each need a unique port. Also you need to include the networkid flag if you want to pair nodes.

    geth --datadir="$ethereum_home/chain1" --ipcdisable --port 30301 --networkid 15 console 2>> console.log

  6. If everything went well you should now be in the geth shell with a chevron (>) prompt

  7. Accounts are a fundamental concept in Ethereum. Create a new account, so you can mine blocks, send/receive ether, etc:

    personal.newAccount().

    Hint: to know which accounts already exist, type personal.listAccounts

  8. Now Create a second node on the same network. Create a second directory in your ‘ethereum_home’ path. Then, open a new console window and enter the following to initialize the node:

    geth --datadir "$ethereum_home/chain2" init "$ethereum_home/genesis.json"

  9. Start your second node. The second node must have the same ‘networkid’ as the first node for the nodes to be able to communicate. Also note that the port for the second node needs to be different than the first node (here 30301 for node1 and and 30302 for node2):

    geth --datadir="$ethereum_home/chain2" --ipcdisable --port 30302 --networkid 15 console 2>> console.log

  10. Now connect the nodes. In the second node instance type admin.nodeInfo and copy the ‘enode’ url from the console output. Then in the first node run the following:

    admin.addPeer(‘enode’ url from above)

  11. Start mining blocks (blocks will be empty at first).

    miner.start()

  12. Stop mining in both consoles

    miner.stop()

  13. Check that the number of blocks is the same in both consoles.

    eth.blockNumber

    If the nodes are correctly paired they should show the same number of blocks.

Create a smart contract

First you will need to install the Solidity IDE (which runs in a browser) to write and compile Ethereum contracts.

  1. Go to https://github.com/ethereum/browser-solidity/tree/gh-pages and download the zip file. Open index.html to run a local copy of Solidity.

  2. Create your first SmartContract: Click the ‘+’ icon in the top left corner of the Solidity IDE to create an empty file. Double click the new file tab title (‘Untitled.sol’) and rename it ‘greeter.sol’. Paste the following simple SmartContract code into the text editor:

    pragma solidity ^0.4.0;

    contract greeter {

    string greeting;

    function greeter(string _greeting) public {

    greeting = _greeting;

    }

    function greet() constant returns (string){

    return greeting;

    }

    function setGreeting(string _greeting) public {

    greeting = _greeting;

    }

    }

  3. Now deploy an instance of the contract to a node in your local blockchain. Stop your first node by typing ‘exit’ at the chevron (‘>’) and restart it with the correct RPC (remote procedure call) flags.

    geth --datadir="$ethereum_home/chain1" --ipcdisable --port 30301 --rpc --rpcport 8545 --rpccorsdomain "*" --networkid 15 console 2>> console.log

  4. At the geth chevron prompt, unlock your account with the following:

    personal.unlockAccount(eth.accounts[0])

  5. Now deploy the contract: Go back to the Solidity IDE in your browser and under the ‘Contract’ tab change the ‘Environment’ selector to ‘Web3 Provider’. A prompt will ask you for the Web3 Provider endpoint.

    Type http://localhost:8545

    Note that this matches the geth parameter (--rpcport 8545) from above.

  6. Now deploy the simple SmartContract. This will deploy the contract to the blockchain in the form of a transaction. In Solidity IDE, under the ‘contract’ tab, find the ‘Create’ button that’s attached to a text field. In that text field type a greeting message like “hi, joe” and click the Create button. This will call the constructor in the SmartContract ‘greeter’ code with the parameter “hi, joe”. You should see a message in the Solidity IDE that the transaction is waiting to be mined.

  7. Go back to your consoles and and start the mining process in both of your nodes.

    miner.start()

  8. Return to Solidity and wait until you see the message change from “transaction is waiting to be mined” to a record of the transaction. You have now deployed the Smart Contract. The deployed contract has an address (location on blockchain) and an interface, which allows you to interact with it.

  9. You can now stop mining. Go to the Geth CLI and type:

    miner.stop()

    Questions? Send us a note!

getting started with ethereum (2024)
Top Articles
The Ultimate Guide on How to Start a Money Making Blog in 2024
Mortgage recasting can help you lower your monthly payment without the hassle of refinancing
Jennifer Hart Facebook
The Definitive Great Buildings Guide - Forge Of Empires Tips
How to change your Android phone's default Google account
Top Financial Advisors in the U.S.
Sam's Club Gas Price Hilliard
Bloxburg Image Ids
Merlot Aero Crew Portal
Big Y Digital Coupon App
The Many Faces of the Craigslist Killer
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
How to Store Boiled Sweets
Drago Funeral Home & Cremation Services Obituaries
Buff Cookie Only Fans
Richland Ecampus
18889183540
Lakewood Campground Golf Cart Rental
C&T Wok Menu - Morrisville, NC Restaurant
Jordan Poyer Wiki
Elbert County Swap Shop
Bento - A link in bio, but rich and beautiful.
Gilchrist Verband - Lumedis - Ihre Schulterspezialisten
Democrat And Chronicle Obituaries For This Week
Tactical Masters Price Guide
R/Mp5
ATM, 3813 N Woodlawn Blvd, Wichita, KS 67220, US - MapQuest
United E Gift Card
Publix Coral Way And 147
Busted! 29 New Arrests in Portsmouth, Ohio – 03/27/22 Scioto County Mugshots
Bee And Willow Bar Cart
Http://N14.Ultipro.com
Metro By T Mobile Sign In
Retire Early Wsbtv.com Free Book
Go Upstate Mugshots Gaffney Sc
Pensacola Cars Craigslist
Blackstone Launchpad Ucf
Fapello.clm
How To Upgrade Stamina In Blox Fruits
Appraisalport Com Dashboard Orders
Samantha Lyne Wikipedia
Giovanna Ewbank Nua
Doe Infohub
'The Night Agent' Star Luciane Buchanan's Dating Life Is a Mystery
Gli italiani buttano sempre più cibo, quasi 7 etti a settimana (a testa)
Meet Robert Oppenheimer, the destroyer of worlds
Buildapc Deals
Cognitive Function Test Potomac Falls
Laurel Hubbard’s Olympic dream dies under the world’s gaze
The Love Life Of Kelsey Asbille: A Comprehensive Guide To Her Relationships
Yoshidakins
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6152

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.