Go API

The Ethereum blockchain along with its two extension protocols Whisper and Swarm was originally conceptualized to become the supporting pillar of web3, providing the consensus, messaging and storage backbone for a new generation of distributed (actually, decentralized) applications called DApps.

以太坊区块链及其两个扩展协议Whisper和Swarm最初被概念化为web3的支持支柱,为称为DApps的新一代分布式(实际上是去中心化)应用程序提供共识,消息传递和存储主干。

The first incarnation towards this dream of web3 was a command line client providing an RPC interface into the peer-to-peer protocols. The client was soon enough extended with a web-browser-like graphical user interface, permitting developers to write DApps based on the tried and proven HTML/CSS/JS technologies.

Web3梦想的第一个体现是一个命令行客户端,它提供了一个对等协议的RPC接口。很快,该客户端通过类似于Web浏览器的图形用户界面进行了扩展,从而允许开发人员基于久经考验的HTML / CSS / JS技术编写DApp。

As many DApps have more complex requirements than what a browser environment can handle, it became apparent that providing programmatic access to the web3 pillars would open the door towards a new class of applications. As such, the second incarnation of the web3 dream is to open up all our technologies for other projects as reusable components.

由于许多DApp的要求比浏览器环境所能满足的要求更为复杂,因此很明显,提供对web3支柱的编程访问将打开通往新型应用程序的大门。因此,web3梦想的第二个体现是将我们的所有技术作为可重用的组件开放给其他项目。

Starting with the 1.5 release family of go-ethereum, we transitioned away from providing only a full blown Ethereum client and started shipping official Go packages that could be embedded into third party desktop and server applications.

从Go-ethereum的1.5发布家族开始,我们从仅提供完整的以太坊客户端的过渡过渡到开始提供可以嵌入到第三方桌面和服务器应用程序中的正式Go软件包。

Note, this guide will assume you are familiar with Go development. It will make no attempts to cover general topics about Go project layouts, import paths or any other standard methodologies. If you are new to Go, consider reading its getting started guides first.

请注意,本指南将假定您熟悉Go开发。它不会尝试涵盖有关Go项目布局,导入路径或任何其他标准方法的常规主题。如果您不熟悉Go,请考虑先阅读其入门指南。

Quick overview

Our reusable Go libraries focus on four main usage areas:

我们可重复使用的Go库专注于四个主要使用领域:

  • Simplified client side account management 简化的客户账户管理
  • Remote node interfacing via different transports 通过不同的传输方式进行远程节点接口
  • Contract interactions through auto-generated bindings 通过自动生成的绑定进行合同交互
  • In-process Ethereum, Whisper and Swarm peer-to-peer node 进程内以太坊,耳语和Swarm对等节点

You can watch a quick overview about these in Peter’s (@karalabe) talk titled “Import Geth: Ethereum from Go and beyond”, presented at the Ethereum Devcon2 developer conference in September, 2016 (Shanghai). Slides are available here.

Peter's Devcon2 talk

Go packages

The go-ethereum library is distributed as a collection of standard Go packages straight from our GitHub repository. The packages can be used directly via the official Go toolkit, without needing any third party tools. External dependencies are vendored locally into vendor, ensuring both self-containment as well as code stability. If you reuse go-ethereum in your own project, please follow these best practices and vendor it yourself too to avoid any accidental API breakages!

go-ethereum库作为标准Go软件包的集合直接从我们的GitHub存储库中分发。这些软件包可以通过Go官方工具包直接使用,而无需任何第三方工具。外部依赖项在本地出售给供应商,从而确保了自包含性和代码稳定性。如果您在自己的项目中重复使用以太坊,请遵循以下最佳做法,并自行进行销售,以免API意外损坏!

The canonical import path for go-ethereum is github.com/ethereum/go-ethereum, with all packages residing underneath. Although there are quite a number of them, you’ll only need to care about a limited subset, each of which will be properly introduced in their relevant section.

go-ethereum的规范导入路径是 github.com/ethereum/go-ethereum,所有软件包都位于其下方。尽管它们很多,但是您只需要关心一个有限的子集,每个子​​集都会在其相关部分中正确介绍。

You can download all our packages via:

$ go get -d github.com/ethereum/go-ethereum/...

You may also need Go’s original context package. Although this was moved into the official Go SDK in Go 1.7, go-ethereum will depend on the original golang.org/x/net/context package until we officially drop support for Go 1.5 and Go 1.6.

您可能还需要Go的原始上下文包。尽管已将其移至Go 1.7中的官方Go SDK中,但在我们正式放弃对Go 1.5和Go 1.6的支持之前,go-ethereum将取决于原始的golang.org/x/net/context包。

$ go get -u golang.org/x/net/context