Web3 with Go and Polygon

Referência · Web3 with Go and Polygon

Polygon Amoy Cheat Sheet

Everything you retype every session, on one printable page.

Network facts

Chain id
80002 — if client.ChainID(ctx) prints anything else, you dialed the wrong network.
Primary RPC
https://rpc-amoy.polygon.technology/ (official public endpoint).
Backup RPCs
If the primary rate-limits you, pick another from the official endpoint list — public endpoints come and go, so the list is the source of truth. Errors and timeouts on a public RPC are usually rate-limiting, not your code: re-run first.
Block time
~2 seconds.
Explorer
amoy.polygonscan.com — paste any address, tx hash, or block number.
Gas token
Test POL (worthless, faucet-supplied).

Faucet field-craft

  • No rush: Lessons 01–02 need zero POL (reads are free; a 0 balance is a correct result). You don't need any POL until Unit 3, and only need ≥2 POL banked before Unit 7. Spend a couple of minutes a day on this, not more.
  • Why every faucet feels gated: public faucets have been farmed by airdrop bots for years, so nearly all of them now require proof you're not a bot — a mainnet ETH balance, a social account, or an NFT mint. This is normal, not a sign you're doing something wrong.
  • Try in this order (confirmed gates as of writing, they change often):

    1. Chainlink faucet — connect MetaMask/WalletConnect/Coinbase Wallet, no mainnet-balance check, no social login. If your course wallet isn't in a browser wallet yet, import wallet.key's hex private key into MetaMask ("Import Account") so tokens land directly on the course address.
    2. Official Polygon faucet — GitHub or X login (GitHub option has been flaky; X needs an account).
    3. ETHGlobal faucet (~0.05 POL/day) — requires minting an ETHGlobal Pack first. Most packs (City, Finalist) gate on having attended a specific event, so this is often not mintable for a new account. Skip if minting says "not eligible."
    4. Alchemy / QuickNode — both require a small ETH balance (≥0.001–0.005 ETH) on Ethereum mainnet in the connected wallet as an anti-sybil check. Only useful if you already hold mainnet ETH somewhere.
  • Real fallback if all faucets stay stuck: a direct wallet-to-wallet transfer of 0.1–0.5 POL from anyone who already holds Amoy POL (ask in a Polygon or ETHGlobal Discord) — costs the sender nothing and skips every faucet gate. This is how most solo learners actually unblock this in practice.
  • Why hoard once it's flowing: Act III (the ERC-3643 suite) burns ~0.6–0.7 POL deployed cleanly, up to ~1.5 with mistakes. Target: ≥2 POL banked before Unit 7.
  • One course wallet: generated in Lesson 01 (wallet.key). Gitignored, testnet-only, never holds real funds.

Go snippets you'll retype forever

connect + sanity-check
client, err := ethclient.Dial("https://rpc-amoy.polygon.technology/")
// client.ChainID(ctx)      -> *big.Int, must be 80002
// client.BlockNumber(ctx)  -> uint64, climbs every ~2s
read a balance (wei)
addr := common.HexToAddress("0x…")
wei, err := client.BalanceAt(ctx, addr, nil) // nil = latest block
big.Int survival rules
a.Cmp(b)   // -1 / 0 / 1 — the ONLY way to compare (== compares pointers)
a.Sign()   // -1 / 0 / 1 — quick zero-check
sum := new(big.Int).Add(a, b)   // results write into the receiver
// money math: integer wei only; big.Float ONLY to format for display
wei ↔ POL
1 POL  = 1_000_000_000_000_000_000 wei   (10^18)
0.01 POL = 10_000_000_000_000_000 wei    (10^16)
max int64 ≈ 9.22 POL in wei — hence *big.Int everywhere

See also

Course glossary · Ethereum Development with Go · ethclient GoDoc