In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Introduction to Go Ethereum
Go Ethereum is one of the three original implementations of the ethernet agreement (as well as C + + and Python). It is written in Go, fully open source and licensed under GNU LGPL v3.
Go Ethereum can be used as a stand-alone client Geth, which you can install on any operating system or as a library that can be embedded in Go,Android or iOS projects.
Build the environment based on the go-ethereum of Etay Square 1. Install go-ethereum
Only the source code installation under the Ubuntu environment is introduced here, and do the following
Install the Go environment
You can download the go-ethereum source code by referring to the go official installation documentation https://golang.org/doc/install:
Go get-d github.com/ethereum/go-ethereum compiles to generate an executable file, which is located in the $GOPATH/bin directory
Go install github.com/ethereum/go-ethereum/cmd/geth2. Start the go_ethereum connection to the Ethernet network startup mode (the complete node on the Taifang network)
By default, geth connects to the official network of Etay Fong, which currently has more than 5 million blocks, and it is full of transactions that cost real money.
$geth console
This command will:
Start geth in Quick Sync mode (by default, you can change it with the-- syncmode flag) to launch Geth's built-in interactive JavaScript console (via the tail console subcommand), which allows you to call all official web3 methods as well as Geth's own management API. This is also optional, and if you leave it outside, you can use geth attach to attach to an already running Geth instance. Log level control
Use-verbosity to control the log level, or if you don't want to see the log, you can use:
$geth-verbosity 0 console development environment startup mode (to test the complete node on the network in Taifang)
When making the transition to a developer, if you want to create an Ethernet Fong contract, you almost certainly don't need real money unless you have control of the entire system. In other words, you don't want to connect to the primary network, but you want to join the test network connected to your node, which is exactly the same as the primary network, but only for Play-Ether.
$geth-testnet console
Console commands have exactly the same meaning as above, and they are also useful on the test network. However, specifying the-- testnet flag will reconfigure your Geth instance:
Instead, using the default data directory (for example, ~ / .ethereum on Linux), Geth embeds itself into a deeper level of the testnet subfolder (~ / .ethereum / testnet on Linux). Note that on OSX and Linux, this also means that a custom endpoint is required to attach to a running testnet node, because by default, geth attach attempts to attach to the production node endpoint. For example. Geth attach / testnet/geth.ipc . Windows users are not affected by this. Instead of connecting to the main Ethernet network, the client connects to the test network, which uses different P2P boot nodes, different network ID and generation status.
Note: although there are some internal safeguards to prevent transactions from being exchanged between the main network and the test network, you should ensure that you always use a separate account for game currency and real money. Unless you move your account manually, Geth will correctly separate the two networks by default and will not establish any accounts between them. Start the connection authority test network mode (Rinkeby test the complete node on the network)
The above test network is a cross-client network based on ethash work proof consensus algorithm. Therefore, due to the low difficulty / security of the network, it has some additional overhead and is more likely to be reorganized. Go Ethereum also supports connecting to an authoritative certification test network called Rinkeby (run by community members). This network is lighter and more secure, but it is only supported by Ethernet Fong.
$geth-- rinkeby-- datadir=path/to/your/databases/and/keystore-- syncmode=fast-- rpc console-- rinkeby: Ethernet test network-- datadir: database and KeyStore data directory-- syncmode: geth has three ways to synchronize data, namely full, fast and light. Of the three methods, full full synchronization is the slowest, it needs to synchronize and check all the blocks down from the creation block. Fast fast synchronization mode is faster than full. It only verifies the nearest 1024 blocks, while light mode is the fastest, because it only verifies the most recent state. The default synchronization mode of geth is fast, which currently has more than 1.8 million blocks on rinkeby. Synchronization takes about half an hour to two hours, so you still need a little patience here. The command to specify the synchronization mode is as follows:
*-- rpc: in order for our application software to connect to geth, we also need to start the rpc server while starting geth
The parameter name parameter describes the marking of the identity blockchain, which is casually filled in to indicate the name of the current network init specifies the location of the Genesis block file, and creates the initial block datadir sets the location of the current blockchain network data storage, port network monitoring port networkid sets the network ID of the current blockchain, used to distinguish different networks, is a digital console startup command line mode, and can execute commands in Geth
Example:
$geth-- rinkeby-- datadir=$HOME/rinkeby-- syncmode=fast-- rpc-- ethstats='KenmyZhang:Respect my authoritahism stats.rinkeby.io'
Note: the KenmyZhang here is the name given to my machine, you need to change it to a name that will not be repeated with others, otherwise there will be mistakes, and there is no need to change it later, this Respect my authoritah! It is a password, universal and does not need to be changed; after running successfully, you can view your machine in https://www.rinkeby.io/#stats.
Configure alternative flag startup mode
Use the dumpconfigsubcommand to export your existing configuration:
Geth-- rinkeby-- datadir=path/to/your/databases/and/keystore-- syncmode=fast-- rpc dumpconfig > ~ / your_config.toml
In this way, when we implement it again in the future, we will directly implement it.
$geth-- config / path/to/your_config.toml
Note: this only applies to geth v1.6.0 and above.
Docker Quick start mode docker run-d-name ethereum-node-v / Users/alice/ethereum:/root\-p 8545 name ethereum-node 8545-p 30303 name ethereum-node 30303\ ethereum/client-go
This will start in Quick Sync mode, with the DB memory capacity of 1GB, just like the command above. It also creates a permanent volume in your home directory to save your blockchain and map the default port. There is also an alpine tag that can be used for a slim version of the image.
If you want to access RPC from other containers and / or hosts, don't forget-- rpcaddr 0.0.0.0. By default, geth is bound to the local interface and the RPC endpoint cannot be accessed from the outside.
Connect Geth nodes programmatically
As a developer, you will soon want to start interacting with Geth and Ethereum networks through your own programs, rather than manually through the console. To solve this problem, Geth has established support for JSON-RPC-based API (standard API and Geth-specific API). These can be exposed through HTTP,WebSockets and IPC (unix sockets on unix-based platforms and named pipes on Windows).
The IPC interface enables and exposes all API supported by Geth by default, while the HTTP and WS interfaces need to be manually enabled, and only part of the API is exposed for security reasons. These can be turned on / off and configured according to your settings
HTTP-based JSON-RPC API options:
-- rpc enables HTTP-RPC server
-- rpcaddr HTTP-RPC server listening interface (default: "localhost")
-- rpcport HTTP-RPC server listening port (default: 8545)
-- API provided by rpcapi through the HTTP-RPC interface (default: "eth,net,web3")
Rpccorsdomain comma-separated list of domains that accept cross-source requests (enforced by browsers)
-- ws enables WS-RPC server
-- wsaddr WS-RPC server listening interface (default: "localhost")
-- wsport WS-RPC server listening port (default: 8546)
-- API provided by wsapi through the WS-RPC interface (default: "eth,net,web3")
-- the origin of wsorigins accepting websockets requests
-- ipcdisable disables IPC-RPC server
-- API provided by ipcapi through the IPC-RPC interface (default: "admin,debug,eth,miner,net,personal,shh,txpool,web3")
-- the file name of the IPC socket / pipe in the ipcpath datazone (escaped by an explicit path)
You need to use the features of your own programming environment (libraries, tools, etc.) to connect to the Geth node configured with the above flags via HTTP,WS or IPC, and you need to say JSON-RPC in all transmissions. You can reuse the same connection for multiple requests!
Note: please understand the security risks caused by opening HTTP / WS-based transport before this! People on the Internet are actively trying to subvert Ethernet nodes with exposed API! In addition, all browser tabs have access to locally running Web servers, so malicious web pages may attempt to subvert locally available API!
Actual combat-build ethernet private network from scratch
Maintaining your own private network is even more important because many of the configurations that are taken for granted in official networks need to be set up manually.
Define the private Genesis state
First, you need to create a Genesis state of your network, and all nodes need to understand and agree. This contains a small JSON file (for example, call it genesis.json):
{"config": {"chainId": 0, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0}, "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "difficulty": "0x20000" "extraData": "," gasLimit ":" 0x2fefd8 "," nonce ":" 0x0000000000000042 "," mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 "," parentHash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 "," timestamp ":" 0x00 "}
The above fields should be fine for most purposes, but we recommend changing the random number to a random value to prevent unknown remote nodes from connecting to you. If you want to fund some accounts in advance for testing, you can populate the alloc field with account configuration:
"alloc": {"0x0000000000000000000000000000000000000001": {"balance": "111111111"}, "0x0000000000000000000000000000000000000002": {"balance": "2222222222"}}
After defining the Geneis state in the above JSON file, you need to initialize each Geth node before starting it to ensure that all blockchain parameters are set correctly:
$geth-- datadir=path/to/your/databases/and/keystore init path/to/genesis.json-- the data directory of the datadir database and KeyStore. Default is "~ / .ethereum".
Method 2: add the following parameters to the parameters of the startup command
-- datadir=path/to/your/databases/and/keystore init path/to/genesis.json
Attached-detailed explanation of the parameters:
Mixhash: hash generated by part of the previous block for mining in conjunction with nonce. Note that the settings of him and nonce need to meet the Yellow paper of Ethernet Square, 4.3.4. The conditions described in Block Header Validity, (44). Nonce: nonce is a 64-bit random number for mining. Note that his and mixhash settings need to meet the Yellow paper of Ethernet Square, 4.3.4. The conditions described in Block Header Validity, (44). Difficulty: it is difficult to set the current block. If it is too difficult, it will be very difficult for cpu mining. Here, set a less difficult alloc: it is used to preset the account number and the number of Ethernet coins used for the account. Because private chain mining is relatively easy, we do not need to preset accounts with coins. We can create them when we need them. Coinbase: miner's account, randomly enter timestamp: set the timestamp of the creation block parentHash: the hash value of the previous block, because it is a creation block, this value is 0 extraData: additional information, you can fill in your personality information gasLimit: this value sets the limit on the total consumption of GAS, which is used to limit the sum of transaction information that the block can contain. Because we are a private chain, it is the largest. Create a rendezvous point
If all the nodes to be run are initialized to the desired Genesis state, you need to start the bootstrap node, which others can use to find each other on the network and / or over the Internet. The method is to configure and run a dedicated boot node:
$bootnode-- genkey=boot.key$ bootnode-- nodekey=boot.keyINFO [03-06 | 17:35:12] UDP listener up self=enode://4cd15426a69ebf094a1cdeda9e6c987752c1108d87bcc6331be10f464e0c5d9e14197495584e58a986d933ad5a39da5fa1dfa84b7f793b4bde94e1578bfaf57e@ [:]: 3030
When bootnode is online, it displays an enode URL that other nodes can use to connect to it and exchange peer information. Be sure to replace the displayed IP address information (most likely [:]) with an externally accessible IP to get the actual enode URL.
Note: you can also use a fully mature Geth node as a boot node, but this is not the recommended way.
The Etay Fong node can be described by URL scheme "enode".
The hexadecimal node ID is encoded in the user name section of the URL and is separated from the host by the @ symbol. The hostname can only be given as an IP address, and the DNS domain name is not allowed. The port in the hostname section is the TCP listening port. If the TCP and UDP ports are different, the UDP port is specified as the query parameter "discport".
In the following example, the node URL describes the node with the IP address of 10.3.58.6 TCP snooping port 30303 and UDP discovery port 30301.
Enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@10.3.58.6:30303 discport=30301
The enode url scheme is used by Node Discovery Protocol and can be used on the client's bootnodes command line option or as an argument to the suggestPeer (nodeURL) function in JSRE.
Start your member node
With bootnode running and externally accessible (you can try telnet to make sure it is indeed accessible), start each subsequent Geth node with the-- bootnodes flag, pointing to the bootnode discovered by that peer. It may also be advisable to separate private network data directories, so specify a custom-datadir flag as well.
$geth-port=listenPort-datadir=path/to/your/databases/and/keystore-bootnodes=
Note: because your network will be completely isolated from the main network and test network, you also need to configure miners to handle transactions and create new blocks for you.
Operate private miners
Mining on the public ethernet network is a complex task because it can only use GPU and requires OpenCL or CUDA-enabled ethminer instances. For information about this setting, see the https://www.reddit.com/r/EtherMining/ or https://github.com/ethereum-mining/ethminer miners repository.
However, in private network settings, a single instance of the CPU collector is sufficient for practical applications, because it can generate a stable block flow at the right time interval without requiring significant resources (considering running on a single thread, not multiple). To start a Geth instance for mining, run it with all the usual flags and extend it by:
Geth-- mine-- minerthreads = 1-- etherbase = 0x0000000000000000000000000000000000000000
This starts digging blocks and transactions on a single CPU thread and logs all processes to the account specified by-- etherbase. You can further adjust mining by changing the default gas limit block to (--targetgaslimit) and accepting a price transaction at (- gasprice).
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.