以太坊客户端是一个软件应用程序,它实现以太坊规范并通过对等网络与其他以太坊客户端进行通信。如果不同的以太坊客户端符合参考规范和标准化通信协议,则可以进行互操作。虽然这些不同的客户端由不同的团队和不同的编程语言实现,但他们都“speak”相同的协议并遵循相同的规则。
The Etherton client is a software application that regulates and communicates with other ether clients via peer-to-peer networks. If different ether clients comply with the referencing and standardized communication protocols, interoperability is possible. While these different clients are performed by different teams and different programming languages, they all “speak” the same protocols and follow the same rules.
以太坊是一个开源项目,源代码在开源(LGPL v3.0)许可下可用,可以免费下载和用于任何目的。开源意味着不仅仅是免费使用。这也意味着以太坊是由一个开源的志愿者社区开发的,任何人都可以修改。
Ether is an open source project that can be sourced under the permission of the Open Source (LGPL v3.0), which can be downloaded and used for any purpose at no cost. Open source means more than free use. It also means that Ether is developed by an open-source volunteer community and can be modified by anyone.
以太坊由称为“黄皮书”的正式规范定义。这与例如比特币形成对比,比特币没有以任何正式方式定义。比特币的“规范”是比特币核心的参考实现,以太坊的规范记录在一篇结合了英语和数学(正式)规范的论文中。除了各种以太坊改进提案之外,此正式规范还定义了以太坊客户端的标准行为。随着对以太坊的重大改变,黄皮书会定期更新。
This is contrasted with, for example, bitcoin, which is not defined in any formal way. Bitcoin’s “norm” is a reference at the heart of bitcoin and is recorded in a paper that combines English and mathematics (formal). In addition to the various proposals to improve it, the formal code defines the standard behaviour of the user community’s clients. The yellow paper will be updated regularly as major changes are made to it.
作为以太坊明确的正式规范的结果,以太网客户端有许多独立开发但可互操作的软件实现。以太网在网络上运行的实现比任何其他区块链更多样化。
As a result of this formal regulation, there are many independently developed, but interoperable, software available on the web. The network operates more diversely on the network than any other block chain.
存在各种基于以太坊的网络,这些网络很大程度上符合以太坊“黄皮书”中定义的形式规范,但它们之间可能相互也可能不相互操作。
There are various networks based on the Taiyeon, which are largely regulated in the form defined in the Taiyeon Book, but they may or may not operate among themselves.
在这些基于以太坊的网络中有:以太坊,以太坊经典,Ella,Expanse,Ubiq,Musicoin等等。虽然大多数在协议级别兼容,但这些网络通常具有要求以太坊客户端软件维护人员进行微小更改以支持每个网络的功能或属性。因此,并非所有版本的以太坊客户端软件都在基于以太坊的区块链上运行。
Among these Ether based networks are: Ether, Ether Classics, Ella, Expanse, Ubiq, Musicoin, and so on. While most of the networks are compatible at the protocol level, these networks usually have the function or attributes of requiring small changes to be made by Taiteng client maintenance to support each network. Thus, not all versions of Ether client software are running on the Ether-based block chain.
目前,以六种不同语言编写的以太坊协议有六种主要实现:Go (Geth), Rust (parity), C++ (cpp-ethereum), Python (pyethereum), Scala (mantis) and Java (harmony)。
At present, there are six main achievements of the Tails agreement in six different languages: Go (Geth), Rust (parity), C++ (cpp-etheium), Python (pytheeum), Scala (mantis) and Java (harmony).
在本节中,我们将介绍两个最常见的客户,Geth和Parity。我们将学习使用每个客户端设置一个节点,并探索它们的一些命令行和应用程序编程接口(API)。
In this section, we will introduce two of the most common clients, Geth and Parity. We will learn to use each client to set a node and explore some of their command lines and application programming interfaces (API).
区块链的健康,弹性和审查抵抗力取决于具有许多独立操作和地理上分散的全节点。每个全节点都可以帮助其他新节点获取区块数据以引导其操作,并为操作员提供所有交易和合约的权威和独立的验证。
The health of the block chain, elasticity and review resistance depend on a number of operational and geographically dispersed full-scale nodes. Each full node can assist other new nodes in obtaining block data to guide their operations and provide operators with the authority and independent validation of all transactions and contracts.
但是,运行全节点将导致硬件资源和带宽的显着成本。全节点必须下载超过80GB的数据(截至2018年4月;取决于客户端)并将其存储在本地硬盘上。随着新交易和区块的增加,这种数据负担每天都在迅速增加。
However, running the full node will result in significant costs for hardware resources and bandwidth. The full node must download more than 80 GB data (as of April 2018; depending on the client) and store them on local hard disks. This data burden increases rapidly every day as new transactions and blocks increase.
以太坊开发不需要在实时网络(主网)上运行的全节点。您可以使用testnet节点(存储较小的公共测试区块链的副本),本地私有区块链或使用服务提供的基于云的以太坊客户端执行几乎所有操作。
You can use the testnet node (storage of copies of smaller public test block chains), local private block chains or cloud-based Itamin clients that use services to perform almost all operations.
您还可以选择运行轻量级客户端,该客户端不存储区块链的本地副本或验证区块和交易。这些客户端提供钱包的功能,可以创建和广播交易。
You can also choose to run a lightweight client that does not store local copies of block chains or authenticate blocks and transactions.
轻量级客户端可用于连接到现有网络,例如您自己的全节点、公共区块链、公共或许可(PoA)测试网或私有本地区块链。实际上,您可能会使用轻量级客户端(如MetaMask,Emerald Wallet,MyEtherWallet或MyCrypto)作为在所有不同节点选项之间切换的便捷方式。
A lightweight client can be used to connect to an existing network, e.g. your own whole node, public block chain, public or licensed (PoA) test network, or private area block chain. In practice, you may use a lightweight client (e.g. MetaMask, Emerald Wallet, MyEther Wallet or MyCrypto) as an easy way to switch between different node options.
术语“轻量级客户端”和“钱包”可互换使用,但存在一些差异。通常,轻量级客户端除了提供钱包的交易功能外,还提供API(例如web3js API)。
The terms “lightweight client” and “mind” are interchangeable, but there are some differences. Normally, lightweight client provides API (e.g. web3js API) in addition to the transaction function of the wallet.
不要将以太坊轻量级钱包的概念与比特币中的简易支付验证(SPV)客户端的概念混淆。SPV客户端验证块头并使用merkle证明来验证区块链中的交易。通常,以太坊轻量级客户端不验证区块头或交易。他们完全信任由第三方运营的完整客户端,以授予他们对区块链的RPC访问权限。
Do not confuse the concept of Taiwan lightweight wallets with the concept of a simple payment certification (SPV) client in Bitco. SPV clients verify blocks and use merkele certificates to verify transactions in block chains. Usually, Taipan lightweight clients do not verify blocks or transactions. They have full confidence in the full client operated by a third party to grant access to the RPC in the block chain.
选择运行全节点有助于各种基于以太坊的网络,但也会为您带来一些轻微到中等的成本。让我们看看一些优点和缺点。
Selecting to run the whole node helps various Ether based networks, but it also costs you a little to medium. Let's see some of the advantages and disadvantages.
优点
- 支持基于以太坊的网络的灵活性和审查区块。
- 权威地验证所有交易。
- 可以与公共区块链上的任何合约互动(无需中间人)。
- 如有必要,可以离线查询(只读)区块链状态(帐户,合约等)。
- 可以在不让第三方知道您正在阅读的信息的情况下查询区块链。
- 可以直接将您自己的合约部署到公共区块链中(无需中介)。
缺点
- 需要大量且不断增长的硬件和带宽资源。
- 第一次初始下载需要几个小时或几天才能完全同步。
- 必须维护,升级并保持在线以保持同步。
无论您是否选择运行全节点,您可能都希望运行公共testnet节点。让我们看看使用公共testnet的一些优点和缺点。
Whether or not you choose to run a full node, you may want to run a public testnet node. Let us see some of the advantages and disadvantages of using a public node.
优点
- 一个testnet节点需要同步和存储更少的数据,大约10GB,具体取决于网络(截至2018年4月)。
- 一个testnet节点可以在几个小时内完全同步。
- 部署合约或进行交易需要测试以太,它没有价值,可以从几个“水龙头”免费获得。
- Testnets是具有许多其他用户和合约的公共区块链,运行“live”。
缺点
- 你不能在testnet上使用“真正的”钱,它在测试以太坊网络上运行。
- 因此,您无法测试真实对手的安全性,因为没有任何利害关系。
- 公共区块链的某些方面无法在testnet上进行实际测试。例如,交易费用虽然是发送交易所必需的,但由于gas是免费的,因此不在testnet上考虑。并且测试网络不会像公共网络那样经历网络拥塞。
对于许多测试目的,最好的选择是使用testrpc节点启动单实例专用区块链。TestRPC创建一个仅限本地的私有区块链,您可以与其进行交互,而无需任何其他参与者。它具有公共testnet的许多优点和缺点,但也有一些差异。
For many test purposes, the best option is to use the testrpc node to start a single example-specific block chain.
优点
- 磁盘上没有同步,而且几乎没有数据。你自己挖掘第一块。
- 无需获取测试以太,您可以“奖励”自己可用于测试的挖掘奖励。
- 没有其他用户,只有你。
- 没有其他合约,只有您在启动它之后部署的合同。
缺点
- 没有其他用户意味着它的行为与公共区块链的行为不同。交易空间或交易顺序没有竞争。
- 除了你之外没有矿工意味着挖掘更容易预测,因此你无法测试公共区块链上发生的某些情况。
- 没有其他合约意味着您必须部署要测试的所有内容,包括依赖项和合约库。
- 您无法重新创建一些公共合约及其地址来测试某些方案(例如DAO合同)。
如果您有时间和资源,则应尝试运行全节点,即使只是为了了解有关该过程的更多信息。在接下来的几节中,我们将下载、编译和运行以太坊客户端Go-Ethereum(Geth)和Parity。这需要熟悉在操作系统上使用命令行界面。无论您选择将它们作为全节点,作为testnet节点还是作为本地私有区块链的客户端运行,都值得安装这些客户端。
If you have the time and resources, try to run the full node, even if you want to know more about the process. In the next few sections, we will download, compile, and run the community client Go-Etheeum (Geth) and Parity. This requires familiar use of the command line interface on the operating system. Whether you choose to run them as full node, as a testnet node or as a customer in a local private block chain, it is worthwhile to install these clients.
在开始之前,您应确保拥有一台具有足够资源的计算机来运行以太坊全节点。您将需要至少80GB的磁盘空间来存储以太坊区块链的完整副本。如果您还想在以太坊测试网上运行完全节点,则至少需要额外的15GB。下载80GB的区块链数据可能需要很长时间,因此建议您使用快速的Internet连接。
Before you start, you should ensure that you have a computer with sufficient resources to run the entire node of the Taiyana. You will need at least 80 GB disk space to store a complete copy of the dyke block chain. If you want to run the full node online in Taiye, you will need at least 15 GB. Downloading the 80 GB block chain data may take a long time, so you are advised to use the fast Internet connection.
同步以太坊区块链是非常输入输出(I / O)密集型。最好有固态硬盘(SSD)。如果您有机械硬盘驱动器(HDD),则需要至少8GB的RAM才能用作缓存。否则,您可能会发现系统太慢而无法跟上并完全同步。
Synchronizes with the Taiwan block chain is very input-intensive (I/ O). Better have a solid-state hard drive (SSD). If you have a mechanical hard drive (HDD), you need at least 8GB RAM to use as a cache. Otherwise, you may find the system too slow to keep up with and fully synchronize.
最低要求
- 具有至少双核的CPU。
- 固态硬盘(SSD),可用空间至少为80GB。
- 最小4GB RAM,如果你有HHD而不是SSD,至少8GB。
- 8 MBit/sec下载Internet服务。
这些是同步基于以太坊的区块链的完整(但已修剪)副本的最低要求。
These are minimum requirements for complete (but trimmed) copies of the synchronised block chain based in Ether.
在撰写本文时(2018年4月),Parity代码库在资源方面往往更少,如果您使用有限的硬件运行,您可能会看到使用Parity的最佳效果。
At the time of writing (April 2018), Parity has often had fewer resources, and if you run with limited hardware, you may see the best use of Parity.
如果您想在合理的时间内同步并存储我们在本书中讨论的所有开发工具、库、客户端和区块链,您将需要一台功能更强大的计算机。
If you want to synchronize and store all the development tools, libraries, client and block chains that we discuss in this book within a reasonable time, you will need a more powerful computer.
推荐规格
- 具有至少四核的快速CPU。
- 16GB+ RAM。
- 具有至少500GB可用空间的快速SSD。
- 25+ MBit/sec下载Internet服务。
很难预测区块链的大小会增加多快以及何时需要更多磁盘空间,因此建议在开始同步之前检查区块链的最新大小。
It is difficult to predict how fast the size of the block chain will increase and when more disk space will be needed, and it is therefore recommended that the latest size of the block chain be checked before the synchronization begins.
以太坊:https://bitinfocharts.com/ethereum/
以太坊经典:https://bitinfocharts.com/ethereum%20classic/
搭建和运行客户端的软件要求(节点)
本节介绍Geth和Parity客户端软件。假设您使用的是类Unix的命令行环境。这些示例显示了在运行Bash shell(命令行执行环境)的Ubuntu Linux操作系统上输入的输出和命令。
This section describes the Gerth and Parity client software. Assuming that you use a command-line environment of the Unix class, these examples show the output and command entered on the Ubuntu Linux operating system that runs the Bash shell (command-line execution environment).
通常,每个区块链都有自己的Geth版本,而Parity则支持多个基于以太坊的区块链(以太坊,以太坊经典,Ellaism,Expanse,Musicoin)。
Usually, each block chain has its own Geth version, while Parity supports multiple Ether-based block chains (Etheria, Etheria Classic, Ellaism, Expanse, Musicoin).
Tip | 在本章的许多示例中,我们将使用操作系统的命令行界面(也称为“shell”),通过“终端”应用程序访问。shell会显示提示; 键入命令,shell响应一些文本和下一个命令的新提示。您的系统上的提示可能看起来不同,但在以下示例中,它由符号表示。在示例中,当您在符号后面看到文本时,请不要键入符号,而是紧跟其后键入命令,然后按Enter执行命令。在示例中,每个命令下面的行是操作系统对该命令的响应。当你看到下一个前缀时,你会知道它是一个新命令,你应该重复这个过程。 |
---|
在我们开始之前,我们可能需要满足一些先决条件。如果您从未在当前使用的计算机上进行任何软件开发,则可能需要安装一些基本工具。对于下面的示例,您需要安装源代码管理系统git;golang,Go编程语言和标准库; 和Rust,一种系统编程语言。
You may need to install some basic tools if you have never made any software development on a computer currently in use. For the example below, you need to install a source-code management system git; golang, Go programming language and standard library; and Rust, a system programming language.
可以按照以下说明安装Git:https://git-scm.com/
可以按照以下说明安装Go:https://golang.org/
Git:
https:
Note | Geth的要求各不相同,但如果你坚持使用Go 1.10或更高版本,你应该能够编译你想要的任何版本的Geth。当然,您应该始终参考您选择的Geth对应的文档。安装在操作系统上或可从系统的软件包管理器获得的golang版本可能远远大于1.10。如果是这样,请将其删除并从golang.org安装最新版本。 |
---|
可以按照以下说明安装Rust:https://www.rustup.rs/
Rust can be installed as described below:
Note | Parity需要Rust1.24版本或更高版本。 |
---|
Parity还需要一些软件库,例如OpenSSL和libudev。要在Linux(Debian)兼容系统上安装它们:
Parity also needs some software libraries, such as OpenSSL and libudev. To install them on Linux (Debian) compatible systems:
对于其他操作系统,请使用操作系统的软件包管理器或按照Wiki说明(https://github.com/paritytech/parity/wiki/Setup)安装所需的库。
For other operating systems, use the package manager of the operating system or install the required library as specified by Wiki ().
现在你已经安装了git,golang,rust和必要的库,让我们开始工作吧!
Now you've installed git, golang, runt and the necessary library, let's get to work!
Parity是全节点以太坊客户端和DApp浏览器的实现。Parity是Rust“从头开始”编写的,这是一种系统编程语言,旨在构建模块化,安全且可扩展的以太坊客户端。Parity由英国公司Parity Tech开发,并根据GPLv3开源许可证发布。
Parity is the realization of the whole node with the Tails client and the DApp browser. Parity is a system programming language designed to build modular, secure and scalable Ether clients. Parity is developed by the British company Paris Tech and issued under the GPLv3 open-source license.
Note | 披露:本书的作者之一Gavin Wood是Parity Tech的创始人,并撰写了大部分Parity客户端。Parity代表已安装的以太坊客户群约28%。 |
---|
要安装Parity,您可以使用Rust包管理器cargo或从GitHub下载源代码。包管理器还是下载源代码,两个选项之间没有太大区别。在下一节中,我们将向您展示如何自己下载和编译Parity。
To install Parity, you can download the source code using the Rust Packet Manager cargo or GitHub. The package manager is still downloading the source code, and there is no big difference between the two options. In the next section, we will show you how to download and compile Parity.
Parity Wiki提供了在不同环境和容器中构建Parity的说明:
https://github.com/paritytech/parity/wiki/Setup
Parity Wiki provided a description of the construction of Parity in different environments and containers:
我们将从源代码构建Parity。这假设您已经使用rustup安装了Rust。
We'll build Parity from the source code. This assumes you've installed Rust using Rustup.
首先,让我们从GitHub获取源代码:
First, let's get the source code from GitHub:
现在,让我们切换到parity目录并使用cargo来构建可执行文件:
Now, let's switch to the parity directory and use cargo to build executables:
如果一切顺利,你应该看到类似的东西:
If everything goes well, you should see something like that:
让我们通过调用--version选项尝试运行parity以查看它是否已安装:
(译者注:mac下会出现“parity: command not found”错误,请参考Fixing Parity Error on a Mac)
Let's try to run parity by calling -- the version option to see if it's installed: 很好!现在已经安装了Parity,我们可以同步区块链并开始使用一些基本的命令行选项。 Good! Parity has been installed, so we can synchronize block chains and start using some basic command line options. Geth是Go语言实现,它被积极开发并被认为是以太坊客户端的“官方”实现。通常,每个基于以太坊的区块链都有自己的Geth实现。如果您正在运行Geth,那么您需要确保使用以下某个仓库链接获取区块链的正确版本。 Geth is a Go language, which is actively developed and considered to be an “official” of Taiyan clients. Usually, each block chain based on Etai has its own Geth. If you are running Geth, then you need to ensure that the right version of the block chain is obtained using one of the following warehouse links. 仓库链接 Repository Link
(translation: mac: there's a "parity: community not found" error, refer to
Note | 您也可以跳过这些说明,并为您选择的平台安装预编译的二进制文件。预编译版本更容易安装,可以在上面的仓库的“release”部分找到。但是,您可以通过自行下载和编译软件来了解更多信息。 |
---|
我们的第一步是克隆git仓库,以获取源代码的副本。
要创建此仓库的本地克隆,请在主目录中或在用于开发的任何目录下使用git命令,如下所示:
Our first step is to clone the Git warehouse to obtain a copy of the source code.
To create the local clone of this warehouse, use the git command in the home directory or under any directory used for development, as follows:
将仓库克隆到本地系统时,您应该看到进度日志:
When you clone the warehouse into a local system, you should see the progress log:
很好!现在我们有了Geth的本地副本,我们可以为我们的平台编译可执行文件。
Good. Now we have a local copy of Geth, and we can compile and translate the executables for our platform.
要构建Geth,请切换到下载源代码的目录并使用make命令:
To build Geth, switch to the directory that downloads the source code and use the make command:
如果一切顺利,您将看到Go编译器构建每个组件,直到它生成geth可执行文件:
If everything goes well, you will see the Go compiler build each component until it generates the geth executable:
让我们运行geth以确保它在停止并更改它的配置之前有效:
Let's run geth to ensure that it is effective before it stops and changes its configuration:
您的geth version命令可能会显示略有不同的信息,但您应该看到与上面的版本日志非常相似的版本日志。
Your geth vension command may display slightly different information, but you should see a version of the log that is very similar to the version above.
最后,我们可能希望将geth命令复制到操作系统的应用程序目录(或命令行执行路径上的目录)。在Linux上,我们使用以下命令:
Finally, we may wish to copy the geth command to the application directory of the operating system (or the directory on the command line execution path). On Linux, we use the following command:
不要开始运行geth,因为它将开始以“缓慢的方式”同步区块链,这将花费太长时间(数周)。基于以太坊的区块链的第一次同步解释了以太坊区块链的初始同步带来的困难。
Do not start running Gerth, because it will start synchronizing the block chain in a “slow way” that will take too long (for weeks). The first synchronization based on the box chain in the Taiwan explains the difficulty of synchronizing the initial block chain in the Taiwan.
通常,在同步以太坊区块链时,您的客户端将下载并验证自创世块以来的每个区块和每个交易。
Usually, when synchronizing the Etherpane block chain, your client downloads and validates each block and each transaction since the creation of the block.
虽然可以通过这种方式完全同步区块链,但同步将花费很长时间并且具有高计算资源要求(更多RAM和更快的存储)。
While fully synchronized block chains in this way, synchronization will take a long time and have high computing resource requirements (more RAM and faster storage).
许多基于以太坊的区块链是2016年底遭遇拒绝服务(DoS)攻击的受害者。受此攻击影响的区块链在进行完全同步时往往会缓慢同步。
Many block chains based on Ether are victims of denial-of-service (DoS) attacks at the end of 2016.
例如,在以太坊上,新客户将快速进展,直至达到2,283,397区块。该区块于2016年9月18日开采,标志着DoS攻击的开始。从该块到块2,700,031(2016年11月26日),交易验证变得非常缓慢,内存密集,I/O密集。这导致每区块的验证时间超过1分钟。以太坊使用硬分叉实施了一系列升级,以解决在拒绝服务中利用的潜在漏洞。这些升级还通过删除垃圾邮件交易创建的大约2000万个空帐户来清理区块链。
For example, at the Etheria, new customers will move fast until they reach 2,283,397. The block was mined on 18 September 2016, marking the beginning of the DoS attack. From the block to block 2,700,031 (26 November 2016), the transaction certification became very slow and the RAM was intense, and I/O was intense. This resulted in more than one minute of validation time per block.
如果您正在同步完整验证,您的客户端将会变慢并可能需要几天或更长时间来验证受此DoS攻击影响的任何区块。
If you are synchronizing the full validation, your client will slow down and may need days or more to verify any block affected by the DoS attack.
大多数以太坊客户端都包含执行“快速”同步的选项,该同步会跳过交易的完整验证,直到它同步到区块链的提示,然后恢复完整验证。
Most of the Taiwan clients include the option to perform " fast " synchronization, which skips the full validation of the transaction until it syncs to the hint of the block chain and then restores the full validation.
对于Geth,启用快速同步的选项通常称为--fast。您可能需要参考所选以太坊链的具体说明。
For Geth, the option to enable rapid synchronization is usually called --fast. You may need to refer to the selection of the Tailing Chain.
对于Parity,对于较旧版本(<1.6),选项为--warp,并且在较新版本(>=1.6)上默认启用(无需设置配置选项)。
For Parity, for older versions (< 1.6), the option is -warp and is enabled by default on the newer version (>=1.6) (no configuration option is required).
Note | Geth和Parity只能在从空区块数据库开始时进行快速同步。如果您已经开始同步而没有“快速”模式,则Geth和Parity无法切换。删除区块链数据目录并从头开始“快速”同步比继续同步完全验证更快。删除区块链数据时,请注意不要删除任何钱包! |
---|
以太坊客户端提供应用程序编程接口(API)和一组远程调用(RPC)命令,这些命令被编码为JavaScript对象表示法(JSON)。您将看到这称为JSON-RPC API。本质上,JSON-RPC API是一个接口,允许我们编写使用以太坊客户端作为网关进入以太坊网络和区块链的程序。
The application programming interface (API) and a group of remote call (RPC) commands are provided as Taiwan clients, which are coded as JavaScript object expression (JSON). You will see this as JSON-RPC API. In essence, JSON-RPC API is an interface that allows us to develop programs that use Taipan clients as gateways to access the Taiyu network and block chains.
通常,RPC接口在端口8545上作为HTTP服务提供。出于安全原因,默认情况下,它仅限于接受来自localhost(您自己的计算机的IP地址为127.0.0.1)的连接。
Normally, the RPC interface is available as a HTTP service at port 8545. For security reasons, by default, it is limited to accepting connections from localhost (your own computer has an IP address of 127.0.0.1).
要访问JSON-RPC API,您可以使用以您选择的编程语言编写的专用库,该库提供与每个可用RPC命令相对应的“stub”函数调用。或者,您可以手动构建HTTP请求并发送/接收JSON编码的请求。您甚至可以使用通用命令行HTTP客户端(如curl)来调用RPC接口。让我们试试(确保您已配置Geth并先运行):
To access JSON-RPC API, you can use a special library in the programming language of your choice, which provides a call for each "stub" function that corresponds to the available RPC command. Alternatively, you can manually construct HTTP requests and send/receive JSON encoding requests. You can even call the RPC interface using a generic command line HTTP client (e.g. curl). Let's try it (ensure you've configured Get and run first):
或者,您可以手动构建HTTP请求并发送/接收JSON编码的请求。您甚至可以使用通用命令行HTTP客户端(如curl)来调用RPC接口。让我们试试(确保您已配置Geth并先运行):
Alternatively, you can manually construct requests for HTTP and send/receive requests for JSON codes. You can even use the generic command line HTTP client (e.g. curl) to call the RPC interface. Let's try it (ensure that you have configured Geth and run first):
使用curl通过JSON-RPC调用web3_clientVersion函数
Use curl to call web3_clieentVersion function via JSON-RPC
在此示例中,我们使用curl建立HTTP连接以寻址http://localhost:8545。我们已经在运行geth,它在端口8545上提供JSON-RPC API作为HTTP服务。我们指示curl使用HTTP POST命令并将内容标识为Content-Type:application/json。最后,我们传递一个JSON编码的请求作为HTTP请求的数据组件。我们的大多数命令行只是设置curl以正确建立HTTP连接。有趣的部分是我们发出的实际JSON-RPC命令:
In this example, we use curl to create HTTP connections to locate . We're running geth, which provides JSON-RPAPI on port 8545 as HTTP service. We instruct Curl to use the HTTP POST command and mark the content as Content-Type:application/json. Finally, we pass a request for JSON code as the data component for HTTP requests. Most of our orders are just to set Curl to correctly build HTTP connections.
JSON-RPC请求根据JSON-RPC 2.0规范进行格式化,您可以在此处看到:http://www.jsonrpc.org/specification
JSON-RPC requests formatting in accordance with JSON-RPC 2.0 specifications, as you can see here:
每个请求包含4个元素:
Each request contains four elements:
- jsonrpc:JSON-RPC协议的版本。这必须是“2.0”。
- method:要调用的方法的名称。
- params:一个结构化值,用于保存在调用方法期间要使用的参数值。该成员可以省略。
- id:客户端建立的标识符,必须包含字符串、数字或NULL值。如果包含,服务器必须在Response对象中回复相同的值。该成员用于关联两个对象之间的上下文。
Tip | id参数主要用于在单个JSON-RPC调用中发出多个请求时,这种做法称为批处理。批处理用于避免每个请求的新HTTP和TCP连接的开销。例如,在以太坊上下文中,如果我们想要在一个HTTP连接中检索数千个交易,我们将使用批处理。批处理时,为每个请求设置不同的id,然后将其与来自JSON-RPC服务器的每个响应中的id匹配。实现此目的的最简单方法是维护计数器并增加每个请求的值。 |
---|
我们收到的回复是:
The responses we received were:
这告诉我们Geth客户端版本1.8.0正在提供JSON-RPC API。
This tells us that the Geth client version 1.8.0 is providing JSON-RPC API.
让我们尝试更有趣的事情。在下一个示例中,我们向JSON-RPC API询问wei中当前的gas价格:
Let's try something more interesting. In the next example, we ask JSON-RPC API about the current gas price in wei:
响应,0x430e23400告诉我们,目前的gas价格是1.8 Gwei(千兆wei或亿wei)。
In response, 0x430e23400 tells us that the current price of Gas is 1.8 Gwei (Gigabywei or billionwei).
https://github.com/ethereum/wiki/wiki/JSON-RPC
Parity有一个特殊的“Geth兼容模式”,它提供了一个与geth提供的相同的JSON-RPC API。要在Geth兼容模式下运行Parity,请使用--geth开关:
Parity has a special "Geth Compatibility Mode" which provides the same JSON-RPC API as that provided by geth. To run Parity in the Geth Compatibility mode, use --get switch:
轻量级客户端提供完整客户端的功能子集。它们不存储完整的以太坊区块链,因此它们设置起来更快,并且需要更少的数据存储。
A lightweight client provides a complete set of functional subsets for the client. They do not store complete Ether block chains, so they are set up faster and require less data storage.
轻量级客户端提供以下一项或多项功能:
A lightweight client provides one or more of the following functions:
- 管理钱包中的私钥和以太坊地址。
- 创建、签名和广播交易。
- 使用数据有效负载与智能合约进行交互。
- 浏览DApps并与之交互。
- 提供外部服务的链接,例如区块浏览器。
- 转换以太单位并从外部来源检索汇率。
- 将web3实例作为JavaScript对象注入Web浏览器。
- 使用由另一个客户端提供/注入浏览器的web3实例。
- 访问本地或远程以太坊节点上的RPC服务。
一些轻量级客户端,例如移动(智能手机)钱包,仅提供基本钱包功能。其他轻量级客户端是完全开发的DApp浏览器。轻量级客户端通常提供全节点以太坊客户端的一些功能,而无需同步以太坊区块链的本地副本。
Some lightweight clients, such as mobile (smart phone) wallets, provide only basic wallet functions. Other lightweight clients are fully developed DApp browsers. Lightweight clients usually provide some of the features of the entire node as a Taiwan client, without synchronizing local copies of the Taiwan block chain.
让我们来看看一些最流行的轻量级客户端及其提供的功能。
Let's look at some of the most popular lightweight clients and the functions they provide.
所有移动钱包都是轻量级客户端,因为智能手机没有足够的资源来运行完整的以太坊客户端。
All mobile wallets are lightweight clients because smartphones do not have sufficient resources to run their full Ether clients.
流行的移动钱包包括Jaxx,Status和Trust Wallet。我们将这些列为流行移动钱包的示例(这不是对这些钱包的安全性或功能的认可或指示)。
Popular mobile wallets include Jaxx, Status, and Trust Wallet. We list these as examples of popular mobile wallets (this is not an endorsement or instruction of the security or function of these wallets).
基于BIP39助记符种子的多币种手机钱包,支持比特币,Litecoin,以太坊,以太坊经典,ZCash,各种ERC20 token和许多其他货币。Jaxx可用于Android,iOS,作为浏览器插件钱包,以及适用于各种操作系统的桌面钱包。在https://jaxx.io上找到它
Multi-currency mobile wallets based on BIP39 assistor seeds, supporting Bitcoin, Litecoin, Etheria, in Taiguan classic, ZCash, various ERC20 token and many other currencies. Jax can be used as a browser plugin wallet for Android, iOS, and as a desktop wallet for all operating systems. Found it on
移动钱包和DApp浏览器,支持各种token和流行的DApp。适用于iOS和Android智能手机。在https://status.im上找到它
Mobile wallets and DApp browsers, supporting various token and popular DApps. For iOS and Android smartphones. Found it on
移动的以太坊,以太坊经典钱包,支持ERC20和ERC223 token。Trust Wallet适用于iOS和Android智能手机。在https://trustwalletapp.com/找到它
Mobile Etheria, supported by ERC20 and ERC223 token with its classic wallet. Trust Wallet applies to iOS and Android smartphones. Found it at
全功能的支持以太坊的移动DApp浏览器和钱包。允许与以太坊应用和token集成。在https://www.cipherbrowser.com上找到它
Full-functional support to mobile DApp browsers and wallets in Taiwan. Allows integration with Etheria applications and token. Found it on
各种钱包和DApp浏览器可用作Chrome和Firefox等Web浏览器的插件或扩展:在浏览器中运行的轻量级客户端。
Various wallets and Dapp browsers can be used as plugins or extensions for Web browsers such as Chrome and Firefox: lightweight clients running in browsers.
一些比较流行的是MetaMask,Jaxx和MyEtherWallet/MyCrypto。
Some of the more popular are MetaMask, Jaxx and MyEther Wallet/MyCrypto.
MetaMask是在[介绍]中引入的,是一个多功能的基于浏览器的钱包、RPC客户端和基本合约浏览器。它适用于Chrome,Firefox,Opera和Brave Browser。在以下位置找到MetaMask:
MetaMask is introduced in [presentation] and is a multifunctional browser-based wallet, RPC client and basic contract browser. It applies to Chrome, Firefox, Opa and Braw Browser. MetaMask is found at the following locations:
乍一看,MetaMask是一个基于浏览器的钱包。但是,与其他浏览器钱包不同,MetaMask将一个web3实例注入浏览器,充当连接各种以太坊区块链的RPC客户端(例如,mainnet,Ropsten testnet,Kovan testnet,本地RPC节点等)。注入web3实例并充当外部RPC服务的网关的能力使MetaMask成为开发人员和用户都非常强大的工具。例如,它可以与MyEtherWallet或MyCrypto结合使用,充当这些工具的web3提供程序和RPC网关。
At first glance, MetaMask is a browser-based wallet. But, unlike other browser wallets, MetaMask injects a web3 example into a browser, serving as a RPC client that connects various e-Team block chains (e.g. Mainnet, Ropsten testnet, Kovan testnet, local RPC node, etc.). The ability to inject the Web3 example and act as a gateway to external RPC services has made MetaMask a powerful tool for both developers and users. For example, it can be used in conjunction with MyEther Wallet or MyCrypto as a web3 provider and RPC gateway for these tools.
Jaxx是智能手机中的移动钱包,也可作为Chrome和Firefox扩展程序使用。找到它:
Jaxx is a mobile wallet in a smartphone and can also be used as a Chrome and Firefox extension. Found it:
MyEtherWallet是一个基于浏览器的JavaScript轻量级客户端,提供:
MyEtherWallet is a browser-based JavaScript lightweight client that provides:
- 一个用JavaScript运行的软件钱包。
- 通往Trezor和Ledger等流行硬件钱包的桥梁。
- 一个web3接口,可以连接到另一个客户端注入的web3实例(例如MetaMask)。
- 可以连接到以太坊完整客户端的RPC客户端。
- 给定合约地址和应用程序二进制接口(ABI)的基本接口,可与智能合约交互。
MyEtherWallet对于测试和硬件钱包的接口非常有用。它不应该用作主要的软件钱包,因为它通过浏览器环境暴露于威胁,并且不是安全的密钥存储系统。
MyEtherWallet is very useful for testing and hardware wallet interfaces. It should not be used as the main software wallet because it is exposed to threats through the browser environment and is not a secure key storage system.
访问MyEtherWallet和其他基于浏览器的JavaScript钱包时必须非常小心,因为它们经常成为网络钓鱼的目标。始终使用书签而不是搜索引擎或链接来访问正确的Web URL。MyEtherWallet可在以下位置找到:
Access to MyEther Wallet and other browser-based JavaScript wallets must be very careful, as they are often the target of cyberfishing. Always use bookmarks instead of search engines or links to access the correct Web URL. MyEtherWallet can find them at the following locations:
就在本书第一版出版之前,MyEtherWallet项目分为两个竞争实现,由两个独立的开发团队指导:在开源开发中调用的“fork”。这两个项目称为MyEtherWallet(原始品牌)和MyCrypto。在拆分时,MyCrypto提供了与MyEtherWallet相同的功能。由于两个开发团队采用不同的目标和优先事项,这两个项目很可能会出现分歧。
Just before the publication of the first edition of the book, the MyEther Wallet project was divided into two competitions, guided by two independent development teams: “fork” for use in open-source development. These two projects are known as MyEther Wallet (original brand) and MyCrypto. At splits, MyCrypto provides the same functionality as MyEther Wallet.
与MyEtherWallet一样,在浏览器中访问MyCrypto时必须非常小心。始终使用书签,或者非常仔细地键入URL(然后将其加入书签以备将来使用)。
Like MyEtherWallet, you must be very careful when you visit MyCrypto in a browser. You always use bookmarks or type URLs very carefully (and then sign them for future use).
MyCrypto可在以下位置找到:
MyCrypto can find it at the following locations:
Mist是由以太坊基金会建造的首个支持以太坊的浏览器。它还包含一个基于浏览器的钱包,这是ERC20令牌标准的首次实现(Fabian Vogelsteller,ERC20的作者也是Mist的主要开发者)。Mist也是第一个引入camelCase校验和的钱包(EIP-155,参见[eip-155])。Mist运行全节点,并提供完整的DApp浏览器,支持基于Swarm的存储和ENS地址。找到它:
Mist is the first to be built by the Etherm Foundation to support Ether. It also contains a wallet based on a browser, which is the first time that the ERC20 standard has been realized (Fabian Vogelsteller, author of ERC20, also the main developer of Mist). Mist is also the first to introduce camelCase verification and wallet (EIP-155, see [eip-155]). Mist runs the entire node and provides a complete Dapp browser to support the Swarm-based storage and ENS address.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论