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

Book cover


Ethereum Development with Go

A little guide 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-book in pdf, mobi, and epub format:

make ebooks

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
Miguel Mota
#golang #node #terminal #linux #decentralization
Miguel Mota
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 complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb

Golang series A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb LearnCodeonline.in 01

Jan 1, 2023
This is from the udemy course: Go: The Complete Developer's Guide (Golang)

Go Udemy course - "Go: The Complete Developer's Guide (Golang)" How to run the file: go run hello-world.go go run <filename>.go GO CLI commands: go ru

Oct 22, 2021
Go: The Complete Developer's Guide (Golang) Udemy Course by Stephen Grider

Go-The-Complete-Developers-Guide Go Command line tools 1. go build - compiles a bunch of go source code files go build

Dec 29, 2021
Go-beginners-guide-project - golang beginners project from tutorialedge.net

Go Beginner's Project Running Locally If you want to run this application locally then run the following commands: $ go run cmd/cli/main.go Build Appl

Jan 2, 2022
Go programming language secure coding practices guide

You can download this book in the following formats: PDF, Mobi and ePub. Introduction Go Language - Web Application Secure Coding Practices is a guide

Jan 9, 2023
Static Analysis with Go - A Practitioner's Guide

Static Analysis with Go - A Practitioner's Guide Hi, and welcome to Static Analysis with Go - A Practitioner's Guide. This is a workshop about writing

Oct 31, 2022
Practical concurrency guide in Go, communication by channels, patterns

Go Concurrency Guide This guide is built on top of the some examples of the book Go Concurrency in Go and Go Programming Language Race Condition and D

Dec 28, 2022
Dec 7, 2021
An online book focusing on Go syntax/semantics and runtime related things

Go 101 is a book focusing on Go syntax/semantics and all kinds of runtime related things. It tries to help gophers gain a deep and thorough understanding of Go. This book also collects many details of Go and in Go programming. The book is expected to be helpful for both beginner and experienced Go programmers.

Dec 29, 2022
Coding along the book
Coding along the book

Learn Go with Tests Art by Denise Formats Gitbook EPUB or PDF Translations 中文 Português 日本語 한국어 Türkçe Support me I am proud to offer this resource fo

Oct 30, 2021
Solutions for the exercises available in the book "A Linguagem de Programação Go" by Alan Donovan and Brian Kernighan

Go Exercises This repository contains possible solutions for the exercises available in the book "A Linguagem de Programação Go (in portuguese)" by Al

Feb 20, 2022
Book Catalogue, Order RESTful API

Book Catalogue, Order RESTful API try on heroku: https://pacific-island-57943.herokuapp.com Note: '/' endpoint redirect to github repository for docum

Dec 13, 2021
Source code of the 100 Go Mistakes book

100 Go Mistakes and How to Avoid Them Source code of 100 Go Mistakes and How to Avoid Them. Table of Contents Chapter 1 - Introduction Chapter 2 - Cod

Dec 30, 2022
The resource repository of the book "gRPC - Up and Running".
The resource repository of the book

The resource repository of the book "gRPC - Up and Running".

Feb 4, 2022
Mastering-go-exercises - Some code examples from Mihalis Tsoukalos book titled Mastering GO

Mastering go exercises This is a training repository. Here are some code example

Feb 16, 2022
Go from the beginning - A book on Go, contains fundamentals but also recipes

Go from the beginning Welcome to Go from the beginning, a free book containing 25+ lessons that will take you from "zero to hero" in the amazing langu

Dec 28, 2022
This is a brief tutorial I created for a couple friends to show how to do some stuff in go and ethereum. Feel free to do any PRs with suggestions

golang-tutorial This is a brief tutorial I created for a couple friends to show how to do some stuff in Go and Ethereum. Milestones Create the environ

Aug 29, 2022
Test-Driven Development code kata in Golang

Bowling Kata Golang Test-Driven Development code kata in Golang Bowling Rules The game consists of 10 frames. In each frame the player has two rolls t

Jan 5, 2022
Boilerplate for writing Go applications without framework using hexagonal application development approach
Boilerplate for writing Go applications without framework using hexagonal application development approach

Boilerplate for writing Go applications without framework using hexagonal application development approach

Dec 2, 2022