GitHub – ethereum/go-ethereum: Official Go implementation of …

Go Ethereum

Official golang implementation of the Ethereum protocol.

Automated builds are available for stable releases and the unstable master branch.Binary archives are published at https://geth.ethereum.org/downloads/.

For prerequisites and detailed build instructions please read theInstallation Instructionson the wiki.

Building geth requires both a Go (version 1.9 or later) and a C compiler.You can install them using your favourite package manager.Once the dependencies are installed, run

or, to build the full suite of utilities:

The go-ethereum project comes with several wrappers/executables found in the cmd directory.

Going through all the possible command line flags is out of scope here (please consult ourCLI Wiki page), but we'veenumerated a few common parameter combos to get you up to speed quickly on how you can run yourown Geth instance.

By far the most common scenario is people wanting to simply interact with the Ethereum network:create accounts; transfer funds; deploy and interact with contracts. For this particular use-casethe user doesn't care about years-old historical data, so we can fast-sync quickly to the currentstate of the network. To do so:

This command will:

Transitioning towards developers, if you'd like to play around with creating Ethereum contracts, youalmost certainly would like to do that without any real money involved until you get the hang of theentire system. In other words, instead of attaching to the main network, you want to join the testnetwork with your node, which is fully equivalent to the main network, but with play-Ether only.

The console subcommand have the exact same meaning as above and they are equally useful on thetestnet too. Please see above for their explanations if you've skipped to here.

Specifying the --testnet flag however will reconfigure your Geth instance a bit:

Note: Although there are some internal protective measures to prevent transactions from crossingover between the main network and test network, you should make sure to always use separate accountsfor play-money and real-money. Unless you manually move accounts, Geth will by default correctlyseparate the two networks and will not make any accounts available between them.

The above test network is a cross client one based on the ethash proof-of-work consensus algorithm. As such, it has certain extra overhead and is more susceptible to reorganization attacks due to the network's low difficulty / security. Go Ethereum also supports connecting to a proof-of-authority based test network called Rinkeby (operated by members of the community). This network is lighter, more secure, but is only supported by go-ethereum.

As an alternative to passing the numerous flags to the geth binary, you can also pass a configuration file via:

To get an idea how the file should look like you can use the dumpconfig subcommand to export your existing configuration:

Note: This works only with geth v1.6.0 and above.

One of the quickest ways to get Ethereum up and running on your machine is by using Docker:

This will start geth in fast-sync mode with a DB memory allowance of 1GB just as the above command does. It will also create a persistent volume in your home directory for saving your blockchain as well as map the default ports. There is also an alpine tag available for a slim version of the image.

Do not forget --rpcaddr 0.0.0.0, if you want to access RPC from other containers and/or hosts. By default, geth binds to the local interface and RPC endpoints is not accessible from the outside.

As a developer, sooner rather than later you'll want to start interacting with Geth and the Ethereumnetwork via your own programs and not manually through the console. To aid this, Geth has built-insupport for a JSON-RPC based APIs (standard APIs andGeth specific APIs). These can beexposed via HTTP, WebSockets and IPC (unix sockets on unix based platforms, and named pipes on Windows).

The IPC interface is enabled by default and exposes all the APIs supported by Geth, whereas the HTTPand WS interfaces need to manually be enabled and only expose a subset of APIs due to security reasons.These can be turned on/off and configured as you'd expect.

HTTP based JSON-RPC API options:

You'll need to use your own programming environments' capabilities (libraries, tools, etc) to connectvia HTTP, WS or IPC to a Geth node configured with the above flags and you'll need to speak JSON-RPCon all transports. You can reuse the same connection for multiple requests!

Note: Please understand the security implications of opening up an HTTP/WS based transport beforedoing so! Hackers on the internet are actively trying to subvert Ethereum nodes with exposed APIs!Further, all browser tabs can access locally running webservers, so malicious webpages could try tosubvert locally available APIs!

Maintaining your own private network is more involved as a lot of configurations taken for granted inthe official networks need to be manually set up.

First, you'll need to create the genesis state of your networks, which all nodes need to be aware ofand agree upon. This consists of a small JSON file (e.g. call it genesis.json):

The above fields should be fine for most purposes, although we'd recommend changing the nonce tosome random value so you prevent unknown remote nodes from being able to connect to you. If you'dlike to pre-fund some accounts for easier testing, you can populate the alloc field with accountconfigs:

With the genesis state defined in the above JSON file, you'll need to initialize every Geth nodewith it prior to starting it up to ensure all blockchain parameters are correctly set:

With all nodes that you want to run initialized to the desired genesis state, you'll need to start abootstrap node that others can use to find each other in your network and/or over the internet. Theclean way is to configure and run a dedicated bootnode:

With the bootnode online, it will display an enode URLthat other nodes can use to connect to it and exchange peer information. Make sure to replace thedisplayed IP address information (most probably [::]) with your externally accessible IP to get theactual enode URL.

Note: You could also use a full fledged Geth node as a bootnode, but it's the less recommended way.

With the bootnode operational and externally reachable (you can try telnet to ensureit's indeed reachable), start every subsequent Geth node pointed to the bootnode for peer discoveryvia the --bootnodes flag. It will probably also be desirable to keep the data directory of yourprivate network separated, so do also specify a custom --datadir flag.

Note: Since your network will be completely cut off from the main and test networks, you'll alsoneed to configure a miner to process transactions and create new blocks for you.

Mining on the public Ethereum network is a complex task as it's only feasible using GPUs, requiringan OpenCL or CUDA enabled ethminer instance. For information on such a setup, please consult theEtherMining subreddit and the Genoil minerrepository.

In a private network setting however, a single CPU miner instance is more than enough for practicalpurposes as it can produce a stable stream of blocks at the correct intervals without needing heavyresources (consider running on a single thread, no need for multiple ones either). To start a Gethinstance for mining, run it with all your usual flags, extended by:

Which will start mining blocks and transactions on a single CPU thread, crediting all proceedings tothe account specified by --etherbase. You can further tune the mining by changing the default gaslimit blocks converge to (--targetgaslimit) and the price transactions are accepted at (--gasprice).

Thank you for considering to help out with the source code! We welcome contributions fromanyone on the internet, and are grateful for even the smallest of fixes!

If you'd like to contribute to go-ethereum, please fork, fix, commit and send a pull requestfor the maintainers to review and merge into the main code base. If you wish to submit morecomplex changes though, please check up with the core devs first on our gitter channelto ensure those changes are in line with the general philosophy of the project and/or get someearly feedback which can make both your efforts much lighter as well as our review and mergeprocedures quick and simple.

Please make sure your contributions adhere to our coding guidelines:

Please see the Developers' Guidefor more details on configuring your environment, managing project dependencies and testing procedures.

The go-ethereum library (i.e. all code outside of the cmd directory) is licensed under theGNU Lesser General Public License v3.0, alsoincluded in our repository in the COPYING.LESSER file.

The go-ethereum binaries (i.e. all code inside of the cmd directory) is licensed under theGNU General Public License v3.0, also includedin our repository in the COPYING file.

Read the original:

GitHub - ethereum/go-ethereum: Official Go implementation of ...

Related Posts

Comments are closed.