Go is a strong fit for blockchain and cryptography work. Its standard library provides audited implementations of hashing (crypto/sha256, crypto/sha3), signatures (crypto/ecdsa, crypto/ed25519, crypto/rsa), authenticated encryption (crypto/aes with GCM, crypto/cipher) and secure randomness (crypto/rand). Go's goroutines and networking make it practical for peer-to-peer nodes, and major blockchain clients such as go-ethereum (Geth) and Hyperledger Fabric are written in Go.
There is no blockchain framework in the standard library. You build the chain from primitives, or use a library such as go-ethereum or Cosmos SDK.
| Need | Package | Notes |
|---|---|---|
| Hashing | crypto/sha256, crypto/sha512, crypto/sha3 | crypto/sha3 is available from Go 1.24 |
| Digital signatures | crypto/ed25519, crypto/ecdsa, crypto/rsa | Ed25519 is the simplest and fastest to use |
| Symmetric encryption | crypto/aes, crypto/cipher | Use AES-GCM, not raw block modes |
| Random numbers | crypto/rand | Never use math/rand for keys or nonces |
| Password hashing | golang.org/x/crypto/argon2, bcrypt | For user passwords, not for blocks |
| Key derivation | crypto/hkdf, crypto/pbkdf2 | Added to the standard library in Go 1.24 |
Do not write your own cryptographic algorithms. Use these packages and keep Go updated, because security fixes ship in minor releases.
Hashes give each block a fingerprint. Changing any byte of the input changes the hash completely. For a single value, sha256.Sum256 is the simplest call.
For large inputs, create a hasher with sha256.New() and write to it incrementally, or use io.Copy(h, file).
Digital signatures prove that a transaction was authorised by the owner of a private key. Ed25519 is the recommended default in new designs. Bitcoin and Ethereum use ECDSA over the secp256k1 curve, which the standard library does not provide, so those projects use libraries such as btcsuite/btcd/btcec or decred/dcrd/dcrec/secp256k1.
For NIST curves, crypto/ecdsa offers ecdsa.SignASN1 and ecdsa.VerifyASN1, which sign a hash of the message.
The snippet needs the crypto/ecdsa, crypto/elliptic, crypto/rand and crypto/sha256 imports. Handle errors in real code instead of ignoring them.
A blockchain is a list of blocks where each block stores the hash of the previous one. This example adds a simple proof of work, where the hash must start with a number of zero hex digits.
This is a teaching model. A production chain also needs signed transactions, Merkle trees, a consensus protocol, peer discovery and networking, usually built with goroutines, net, gRPC or libp2p.
Use authenticated encryption so tampering is detected. Generate a fresh random nonce for every message and store it with the ciphertext.
map iteration order is random, so never hash a marshalled map without sorting.crypto/subtle.ConstantTimeCompare.govulncheck to catch vulnerable dependencies, and consider fuzzing parsers for transactions and blocks.Yes. Go-ethereum, Hyperledger Fabric and Cosmos are written in Go, and the language offers fast compilation, simple concurrency and static binaries.
Ed25519 for new systems. Choose ECDSA with secp256k1 only when you must be compatible with Bitcoin or Ethereum.
No. math/rand is predictable. Use crypto/rand for keys, nonces and salts.
No. It demonstrates hash chaining and proof of work only. It has no signatures, networking or consensus.
Go's standard library gives you SHA-256, Ed25519, ECDSA and AES-GCM, which cover the cryptography behind most blockchains. Build learning projects from hashing and proof of work, rely on established frameworks for real networks, and follow strict key-handling and deterministic-encoding practices.