2019-11-05 06:46:00 -06:00
|
|
|
---
|
|
|
|
title: Go API
|
2021-06-30 08:21:21 -05:00
|
|
|
sort_key: C
|
2019-11-05 06:46:00 -06:00
|
|
|
---
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*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
|
2021-01-25 08:30:13 -06:00
|
|
|
standard methodologies. If you are new to Go, consider reading its [getting started guides][go-guide] first.*
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
## Quick overview
|
|
|
|
|
|
|
|
Our reusable Go libraries focus on four main usage areas:
|
|
|
|
|
|
|
|
- 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
|
|
|
|
|
|
|
|
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
|
2021-01-25 08:30:13 -06:00
|
|
|
in September, 2016 (Shanghai). Slides are [available here][peter-slides].
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
[![Peter's Devcon2 talk](https://img.youtube.com/vi/R0Ia1U9Gxjg/0.jpg)](https://www.youtube.com/watch?v=R0Ia1U9Gxjg)
|
|
|
|
|
|
|
|
## 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!
|
|
|
|
|
|
|
|
The canonical import path for `go-ethereum` is `github.com/ethereum/go-ethereum`, with all
|
2021-01-25 08:30:13 -06:00
|
|
|
packages residing underneath. Although there are [quite a number][go-ethereum-dir] of
|
|
|
|
them, you'll only need to care about a limited subset, each of which will be properly
|
|
|
|
introduced in their relevant section.
|
2019-11-05 06:46:00 -06:00
|
|
|
|
|
|
|
You can download all our packages via:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ go get -d github.com/ethereum/go-ethereum/...
|
|
|
|
```
|
|
|
|
|
2021-01-25 08:30:13 -06:00
|
|
|
[go-guide]: https://github.com/golang/go/wiki#getting-started-with-go
|
|
|
|
[peter-slides]: https://ethereum.karalabe.com/talks/2016-devcon.html
|
|
|
|
[go-ethereum-dir]: https://pkg.go.dev/github.com/ethereum/go-ethereum/#section-directories
|