Go does not write smart contracts for Ethereum (those are written in Solidity or Vyper), but it is widely used to talk to blockchains and to build the infrastructure around DeFi: nodes, indexers, bots, wallets and APIs. The official Ethereum client, go-ethereum (geth), is itself written in Go and exposes ethclient and generated contract bindings that you use from your own programs.
The Go standard library helps with the parts every blockchain client needs: math/big for exact token amounts, encoding/hex and crypto for keys and hashes, context for timeouts and net/http for JSON-RPC. This guide shows how those pieces fit together.
| Use | Examples |
|---|---|
| Blockchain clients and nodes | go-ethereum, many other chain implementations |
| Application frameworks | Cosmos SDK chains, Hyperledger Fabric chaincode (Go is supported) |
| Backend services | Indexers, event listeners, price and liquidation bots, payment APIs |
| Tooling | Transaction signers, monitoring, test harnesses |
On Ethereum-style chains the contract logic runs on-chain in the EVM, while Go code reads state, sends signed transactions and reacts to events. Keep this split in mind: Go is the client, not the contract language, except on platforms such as Hyperledger Fabric where chaincode can be Go.
Add the dependency with go get github.com/ethereum/go-ethereum. The following program connects to a node over JSON-RPC and prints an account balance in ETH. Pass the RPC URL through an environment variable and never hard-code provider keys.
Balances are returned in wei, where 1 ETH is 10^18 wei, so they overflow uint64 and must be handled as *big.Int.
Compile a Solidity contract to get its ABI, then generate type-safe Go code with geth's abigen tool:
Newer geth releases also offer a v2 binding generator (abigen --v2); check the current go-ethereum documentation for the API your version uses. The generated code lets you call read-only functions and filter events without hand-encoding data:
ERC-20 tokens report amounts in raw units, so divide by 10^decimals (read the decimals() function) before showing users a number.
DeFi code deals with value, so precision is a security matter.
math/big (big.Int) for token amounts and never float64, which cannot represent most decimal values exactly.eth_call or EstimateGas before sending them.Private keys control funds, so treat them as the most sensitive data you hold.
Run a local chain such as a geth dev node, Anvil or Hardhat, and use geth's simulated backend (ethclient/simulated) in Go unit tests. These give you funded accounts and instant blocks, so you can test deposits, events and failure paths deterministically.
Not for Ethereum; contracts there are written in Solidity or Vyper. You can write chaincode in Go for Hyperledger Fabric and build Cosmos SDK modules in Go.
It is the official Go implementation of the Ethereum protocol, usable both as a node and as a library for clients, with ethclient for RPC and abigen for contract bindings.
Floating point cannot represent most decimal fractions exactly, and token balances can exceed 64-bit integer range, so math/big is required for correct results.
The language is not the main risk. Key custody, contract audits, input validation and monitoring decide whether a service is safe.
Use Go as the client and infrastructure layer for smart contracts and DeFi: ethclient to read chain state, abigen bindings to call contracts, math/big for exact amounts, and context timeouts everywhere. Protect keys, simulate before sending, test on local chains and never rely on floating point for money.