📖 A little book on Ethereum Development with Go (golang)

Book cover


Ethereum Development with Go

A little book on Ethereum Development with Go (golang)

License Mentioned in Awesome Go PRs Welcome

Online

https://goethereumbook.org

E-book

The e-book is avaiable in different formats.

Languages

Contents

Help & Support

Development

Install dependencies:

make install

Run gitbook server:

make serve

Generating e-books:

make pdf ebook mobi

Visit http://localhost:4000

Contributing

Pull requests are welcome!

If making general content fixes:

  • please double check for typos and cite any relevant sources in the comments.

If updating code examples:

  • make sure to update both the code in the markdown files as well as the code in the code folder.

If wanting to add a new translation, follow these instructions:

  1. Set up development environment

  2. Add language to LANGS.md

  3. Copy the the en directory and rename it with the 2 letter language code of the language you're translating to (e.g. zh)

  4. Translate content

  5. Set "root" to "./" in book.json if not already set

Thanks

Thanks to @qbig and @gzuhlwang for the Chinese translation.

And thanks to all the contributors who have contributed to this guide book.

License

CC0-1.0

Owner
Comments
  • Smart contract compile abi edits

    Smart contract compile abi edits

    Corrections:

    • Updated solc code examples to include -o flag, necessary to get solc to output binary files instead of printing to terminal (https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html)
    • Tested with docker image ethereum/solc:0.4.24 which uses 0.4.24+commit.e67f0147.Linux.g++ instead of 0.4.24+commit.e67f0147.Emscripten.clang (since implementation shouldn't differ significantly between platforms).
    • Updated corresponding section in Full Code.

    Improvements:

    • Added headings
    • Clarified purpose of chapter in lead paragraph.
    • Added section to use docker solc.
    • Removed "version" of solc at the end of Full Code section. Instead, added version used in installation section.
  • Cannot get transaction's field

    Cannot get transaction's field "From"

    https://github.com/miguelmota/ethereum-development-with-go-book/blob/master/code/transactions.go - this code don't show transaction's field "From".

    For instance, for transaction https://etherscan.io/tx/0x5d49fcaa394c97ec8a9c3e7bd9e8388d420fb050a52083ca52ff24b3b65bc9c2 it shows nothing.

    For transaction https://etherscan.io/tx/0x36368eb4665367100bcb46427e8ac39b7873abfca2015116c478f84642a8812d it shows 0x0000000000000000000000000000000000000000

  • code out dated

    code out dated

    hi Miguel,

    The below method does not exist anymore for types.Transaction

    	ts := types.Transactions{signedTx}
    	rawTxBytes := ts.GetRlp(0)
    

    so, this file should update

    I test with go ethereum v1.10.2

    I find there are another two functions should do this:

    https://github.com/ethereum/go-ethereum/blob/beee6b77a0ca8c26881dc2bb17c58e996c90a0c6/core/types/transaction.go#L119

    https://github.com/ethereum/go-ethereum/blob/beee6b77a0ca8c26881dc2bb17c58e996c90a0c6/core/types/transaction.go#L86

    but I don't know what to put in the method param (w io.Writer)

  • abigen for complex contract example

    abigen for complex contract example

    Hi, for all the example within the book, the contract is simple. What if the contract is a complex one(with many libraries and helper contract in it)?

    Let's say, uniswap StakingRewards contract https://etherscan.io/address/0xCA35e32e7926b96A9988f61d510E038108d8068e#code

    Can you demonstrate how to interact with it? Many abi and bin file will generate, but specifically, I want interactive with the contractStakingRewards.

    Also, I try to interact with TetherToken https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#code

    mkdir usdt
    cd usdt
    # touch TetherToken.sol and put code in it
    solc --abi TetherToken.sol --out abi
    solc --bin TetherToken.sol --out bin
    abigen --bin=bin/TetherToken.bin --abi=abi/TetherToken.abi --pkg=usdt --out=usdt.go
    

    then I get an error

    Fatal: Failed to generate ABI binding: duplicated identifier "totalSupply"(normalized "TotalSupply"), use --alias for renaming
    
  • "403 Forbidden" when using "client.BalanceAt(context.Background(), account, blockNumber)"

    I run the code in this page. The logs are:

    13565093091594031083
    2019/12/09 16:21:15 403 Forbidden {"jsonrpc":"2.0","id":2,"error":{"code":-32002,"message":"project ID is required to access archive state","data":{"see":"https://infura.io/dashboard"}}}
    

    It shows that client.BalanceAt(context.Background(), account, nil) return the balance, but balanceAt, err := client.BalanceAt(context.Background(), account, blockNumber) not.

    I wonder what's the reason here and how to fix it. Thanks a lot if anyone can help me.

  • Go doesn't

    Go doesn't "cast" types; corrected one instance as eg of change

    Go doesn't "cast" types — would be more accurate to describe this as a type assertion, to correctly reflect what is going on with the Go code.

    Not casting because priv.Public() returns an interface, which has an underlying type of *ecdsa.PublicKey. Calling publicKey.(*ecdsa.PublicKey) doesn't perform a conversion, but instead asserts *ecdsa.PublicKey as the resulting variable's type. If *ecdsa.PublicKey is not the underlying type of the variable it is performed on, the operation panics. The underlying type of the variable the type assertion is called on never changes.

    If change is ok, will make changes across the rest of the guide.

    source: https://stackoverflow.com/a/19579058

  • SubscribeFilterLogs: The method eth_logs does not exist/is not available

    SubscribeFilterLogs: The method eth_logs does not exist/is not available

    Hello @miguelmota I am following up your awesome book. My requirement is to read the event log of a Transfer(from, to, value) function. I am using SubscribeFilterLogs for continuous log streaming and updating my other dbs.

    But I am little bit stuck head over to this obfuscating error msg:

    The method eth_logs does not exist/is not available

    I have posted the issuse on slack:golang#ethereum room

    I am quiet sure, error is pooping from this line: https://github.com/miguelmota/ethereum-development-with-go-book/blob/082005828d9647ac6ecd2684a340e55f7b91f692/code/event_subscribe.go#L21-L26

    But couldn't figure out why though. The closest google match relation I found is on this thread: https://github.com/ethereum/go-ethereum/issues/310#issuecomment-75984471

    Am I missing something import here. I have just started the websocket with admin.startWS("0.0.0.0", 8546, "*","*") , I am sure, I can telnet to that port.

    /cc @miguelmota

  • Question if you don’t mind on using Ganache

    Question if you don’t mind on using Ganache

    Hi @miguelmota,

    Fantastic work on this book it’s written very well and so streamlined for getting up to speed.

    Question for you though: do you think you can show an example of getting the Go client talking to Ganache which seems to be the de facto development version of the Blockchain?

    I mean, is it as simple as changing the DNS name to point to the local instance of Ganache?

    I’d like to get that working but I haven’t investigated what it would all take but thought it would be useful in this book.

    What do you think? And great work.

    -Deckarep (Ralph)

  • website doesn't work & can't build the book from source

    website doesn't work & can't build the book from source

    website doesn't work both on mobile and desktop, something about an incorrect time of my computer / mobile

    doesn't build from source due to node-gyp. Tried node v8, v10, v12 and v14

  • deploy contract and call a function in one go

    deploy contract and call a function in one go

    hi Miguel,

    Usually, the process is to deploy contact first and then call the function.

    But now the cost for deploy a contract is high.

    I wonder if I can deploy a contract and call a function within one transaction?

    You may think why I want to do this because it's a special temporary contract, I just need to call the function once in mainnet , and what's more, I don't really need to submit it to chain, I just want to estimate gas for that function.

  • Unpack parameters has changed

    Unpack parameters has changed

    In the ebook, ABI.Unpack takes three arguments: interface{}, string and []byte. This seems to have changed in the recent versions of geth, which now has Unpack not take an interface, and instead returns a []interface{} representing the event's data.

  • Update

    Update "Writing to a Smart Contract"

    Update "Writing to a Smart Contract" to wait for transaction to be mined.

    Without waiting, the value returned is empty while the tx was just sent.

  • Update

    Update "Reading ERC-20 Token Event Logs" to Solidity 0.8.13 and Geth …

    Update "Reading ERC-20 Token Event Logs" to Solidity 0.8.13 and Geth 1.10.17

    About renaming abi.Unpack to abi.UnpackIntoInterface: https://github.com/ethereum/go-ethereum/pull/21091

  • transfer_token.go outdated, needs update, example provided

    transfer_token.go outdated, needs update, example provided

    Current transfer_token.go is outdated. Unsure of when this happened but the current method of transacting ERC-20 tokens looks something like this:

    https://gist.github.com/ckruger097/a156d04a5f3542eac20e6eea5129946d

    Note: This is done from my own research, this may not be best practice but it has worked as a PoC. It may also be worth mentioning I created the token mentioned in the comments using https://vittominacori.github.io/erc20-generator/ & transferred to MetaMask first. Then sent the tokens to my local geth account running on a light node. Hopefully this helps someone.

A simulation to create an order book.

order-book-demo A simulation to create an order book. Operations The order book will require the following operations Add - Submits and Order Cancel -

Jun 27, 2022
A fast and easy-to-use gutenberg book downloader

Gutenberg Downloader A brief description of what this project does and who it's for Usage download books Download all english books as epubs with imag

Jan 11, 2022
The library solves the task of recalculating the exchange order book

fastme (fast golang matching engine) library Design The library solves the task of recalculating the exchange order book. A classic matching engine co

Jul 29, 2022
Print debugging, but a little bit nicer

testlog Print debugging, but a little bit nicer. The use case this is primarily designed for is effectively debugging problematic, flaky tests.

Oct 11, 2021
Barry is a silly little thing I wanted to try, feel free to screenshot.

Barry What is Barry? Barry is a silly little thing I wanted to try, feel free to screenshot. If you manage to get panics after being told not to do th

Nov 6, 2021
Fynodoro is the little widget for doing Pomodoro.

Fynodoro is the little widget for doing Pomodoro.

May 24, 2022
A little tool to create small QR code cards for vaccination/test proof.

Icedream's fancy vaccination/test certificate card tool This is just a tool I wrote to transform my vaccine certificate QR codes into something I can

Dec 16, 2021
A little repository for my Advent of Code 2021 solutions in Go

Advent of Code 2021 What's this repo all about? Well, this is a collection of code written in Golang to solve the daily problems presented in Advent o

Dec 12, 2021
The primary place where Optimism works on stuff related to Optimistic Ethereum
The primary place where Optimism works on stuff related to Optimistic Ethereum

The Optimism Monorepo TL;DR This is the primary place where Optimism works on stuff related to Optimistic Ethereum. Documentation Extensive documentat

Aug 8, 2022
Golang CS:GO external base. Development currently halted due to compiler/runtime Golang bugs.

gogo Golang CS:GO External cheat/base. Also, my first Golang project. Wait! Development momentarily halted due to compiler/runtime bugs. Disclaimer Th

Jun 25, 2022
Software of development with Golang
Software of development with Golang

Go-Simple-Rest-Api Description This repository is a Software of Development with Go,Mux,etc Installation Using Go 1.16.3 Server preferably. DataBase U

Dec 13, 2021
Pango GINX is a GO development utility library for GIN.
Pango GINX is a GO development utility library for GIN.

Pango GINX Pango GINX is a GO development utility library for GIN. Package Description gindump a http request/response dumper middleware for gin ginfi

Feb 2, 2022
Module to ease interaction with Pact's development server & ScalableBFT

go-pact Module to ease interaction with Pact's development server & ScalableBFT Install go install github.com/jfamousket/[email protected] Functions H

Dec 9, 2021
Radiant is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

Radiant is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

Mar 22, 2022
Belajar Golang Install Golang

Golang belajar Golang Install Golang = download di https://golang.org/dl/ = pilih yg Zip = extract file zipnya = buka foldernya - copy folder go = pas

Nov 15, 2021
Golang-module-references - A reference for how to setup a Golang project with modules - Task Management + Math Examples

Golang Module Project The purpose of this project is to act as a reference for setting up future Golang projects using modules. This project has a mat

Jan 2, 2022
Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Dec 31, 2021
Minimalistic, pluggable Golang evloop/timer handler with dependency-injection

Anagent Minimalistic, pluggable Golang evloop/timer handler with dependency-injection - based on codegangsta/inject - go-macaron/inject and chuckpresl

Jan 26, 2022
GoLang Library for Browser Capabilities Project

Browser Capabilities GoLang Project PHP has get_browser() function which tells what the user's browser is capable of. You can check original documenta

Jul 22, 2022