Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Ethereum Cookbook

You're reading from   Ethereum Cookbook Over 100 recipes covering Ethereum-based tokens, games, wallets, smart contracts, protocols, and Dapps

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789133998
Length 404 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Manoj P R Manoj P R
Author Profile Icon Manoj P R
Manoj P R
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started 2. Smart Contract Development FREE CHAPTER 3. Interacting with the Contract 4. The Truffle Suite 5. Tokens and ICOs 6. Games and DAOs 7. Advanced Solidity 8. Smart Contract Security 9. Design Decisions 10. Other Protocols and Applications 11. Miscellaneous 12. Other Books You May Enjoy

Setting up a node and participating in a network

Here, you will learn how to set up a node using the geth command-line tool. You will also see how to connect to a public network and perform operations such as ledger syncing and mining.

Getting ready

You will need a working installation of the geth command-line interface. You can also start a node with parity or any other Ethereum protocol implementation, but the steps may differ for each client.

Commands starting with $ have to be run on the command prompt/terminal and those starting with > will work only on the web3 JavaScript console.

How to do it...

  1. Verify your installation by running the following version command:
$ geth version
  1. Start your node with the following command:
$ geth

This will start an Ethereum node and will connect with the main network. As soon as it finds any peer nodes, it will start downloading the blocks from them.

You can configure the parameters before starting a node. This will help you do things like connect to a different network, expose APIs, and much more. Let's look at a sample initialization and the parameters used in it:

$ geth --networkid 3 --datadir "./ropsten-db" --keystore "./ropsten-keys" --syncmode "fast" --rpc --rpcport "8546" --rpcapi "web3,eth,miner,admin" --rpccorsdomain "*" --port 30301 console

Let's look into each parameter in detail:

  • --networkid <id>: A parameter to identify each network. You can either connect to the main/test network (1=Frontier(default), 2=Morden (disused), 3=Ropsten(PoW), 4=Rinkeby(PoA)) or any private network that you have set up.
  • --datadir <path>: Directory path for storing the blockchain database and keystore. You can change the default keystore directory with the --keystore parameter.
  • --syncmode <mode>: A parameter to specify the type of sync method. You can choose fast, full, or light, based on your needs.
  • --rpc: Enables an RPC server through HTTP. You can also change parameters such as --rpcaddr, --rpcport, and --rpcapi.
  • --rpccorsdomain <list>: Domains from which cross-domain requests are accepted. Use * as a wildcard or specify domains as a comma-separated list.
  • --port <port>: Changes the default network listening port (30303).
  • --console: Starts the web3 JavaScript console.
If you get stuck anywhere, you can always make use of the inbuilt help interface. Just enter geth help and it will return a comprehensive list of all commands with their respective description that you can run using geth.
  1. It might take a few minutes to identify the peers that are already on the network. Run the following command to return the list of peers that are currently connected to your node. Your node will start syncing once it finds at least one peer:
> admin.peers
  1. Check the current syncing status by running the following command. It will return false if not syncing:
> eth.syncing
  1. Run the geth attach command if you would like to connect to this node from a different console. You can also explicitly specify the host and the port. In our case, it is localhost and 8546:
$ geth attach http://localhost:8546
Your firewall may restrict the node from communicating with an external peer. This can cause issues with the synchronization process. Also, ensure that you are not exposing your RPC APIs to the internet, which can result in attacks.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime