Go for Blockchain Infrastructure

Where Go lives in the stack: clients like go-ethereum, Cosmos SDK chains, indexers, bots and RPC tooling.

10 min read·5 quiz questions

Why so much infrastructure is Go

Go compiles to a single static binary, has cheap concurrency and a large standard library — a good fit for long-running network daemons. go-ethereum (geth) is a reference Ethereum client, and the Cosmos SDK with CometBFT/Tendermint lets teams build application-specific chains in Go.

  • geth: execution client, JSON-RPC server, devnet tooling.
  • Cosmos SDK: modules, staking, IBC — chains as Go applications.
  • Most indexers, relayers and monitoring bots are Go services.

Concurrency you actually use

A goroutine is a cheap managed thread started with the go keyword; channels pass values between them. Peer connections, block subscriptions and worker pools map naturally onto this model, and context.Context propagates cancellation and deadlines through the whole call tree.

  • One goroutine per subscription or peer is normal.
  • Use channels or mutexes to share state — never unsynchronised writes.
  • Always pass a context so shutdown is clean.

Reading a chain from Go

With go-ethereum's ethclient you dial an RPC endpoint and call typed methods: HeaderByNumber, BalanceAt, FilterLogs. abigen generates a Go binding from an ABI, giving compile-time-checked contract calls — the server-side counterpart of ethers.js in the browser.

Contract or service?

Put rules that must be trustless and enforced on-chain in the contract. Put anything needing history, aggregation, scheduling or secrets in a Go service that reads events and stores derived data. Backfilling logs and handling reorgs is indexer work, not contract work.

Key terms

geth
go-ethereum, the Go Ethereum execution client and JSON-RPC server.
Cosmos SDK
Go framework for building application-specific blockchains.
Goroutine
Lightweight concurrent function managed by the Go runtime.
abigen
Tool generating typed Go contract bindings from an ABI.
Indexer
Service that reads chain events and stores queryable derived data.

Chapter quiz

5 questions · pass mark 75%
  1. 1. Which of these is written in Go?

  2. 2. A goroutine is…

  3. 3. abigen is used to…

  4. 4. Aggregating a year of staking history for a dashboard belongs in…

  5. 5. Why pass a context.Context through an indexer's call tree?

Answer every question to submit. Progress for go-for-blockchain-infra is saved in this browser.