Lesson 05 · Web3 with Go & Polygon
So far you've only read the chain — reads need no permission. But your client's backend must eventually write: deploy the token, mint shares, move them. Every write is a transaction, and every transaction must be signed by a private key. This lesson is the theory of keys — the heart of Web3 — and ends with a Go program that mints a brand-new wallet you'll use for the rest of the course.
It all starts with one secret random number: the private key. Everything else is computed from it, one direction only — you can go down the chain, never back up.
secp256k1 curve). Safe to share. You can't reverse it back to the private key.0x…. This is the public name of the account — the thing you read balances of.
private key → public key → address. A one-way street. That asymmetry is the
entire security model.
To move shares, your backend signs the transaction with the private key. The network checks the signature against the sender's public key — no secret is ever revealed, yet everyone can verify the sender authorized it. This is why the industry mantra is:
main.go
package main
import (
"crypto/ecdsa"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
// 1. A brand-new private key — the one secret that controls the account.
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
}
privBytes := crypto.FromECDSA(privateKey)
fmt.Println("private key:", hexutil.Encode(privBytes)) // keep this SECRET
// 2. Derive the public key from the private key.
publicKey, ok := privateKey.Public().(*ecdsa.PublicKey)
if !ok {
log.Fatal("could not cast public key to ECDSA")
}
// 3. The address is derived from the public key.
address := crypto.PubkeyToAddress(*publicKey)
fmt.Println("address: ", address.Hex())
}
Run it:
terminal
go run main.go
private key: 0x9c6f... (SECRET — never share or commit)
address: 0x8A2f1C...c47B
0, because a fresh account is empty until
funded. Now grab test POL for it from the
Amoy faucet and read it again.
1. What is the correct derivation direction?
2. An account's 0x… address is derived from a hash of the…
3. Signing a transaction proves authorization while keeping what hidden?
4. A freshly generated account, before funding, has a balance of…
I'm your teacher — ask me anything. Want to understand ECDSA and secp256k1 more
deeply? Curious how a seed phrase relates to this private key? Ready to load the key safely
from an env var and sign your first write transaction? That's exactly where we go next — ask.