Mainnet, Testnet3, Testnet4, Signet and Regtest
GOLANG + BITCOIN SCRIPT — Stage 001, Lesson 11 of 12.
Concept
Mainnet carries real economic value. Testnet3 and Testnet4 are separate public testing chains; BIP94 specifies Testnet4 changes. Signet uses a challenge for block validity and regtest allows controlled local block generation. Test coins are not intended to have monetary value.
Engineering practice
Native witness addresses use bc on mainnet, tb on testnet3, testnet4 and signet, and bcrt on regtest. The shared tb prefix cannot distinguish three chains. The example rejects unknown network names. For integration testing, verify node identity explicitly and never reuse real wallet secrets.
Source example
1package main
2
3import (
4 "errors"
5 "fmt"
6)
7
8func hrp(network string) (string, error) {
9 switch network {
10 case "mainnet":
11 return "bc", nil
12 case "testnet3", "testnet4", "signet":
13 return "tb", nil
14 case "regtest":
15 return "bcrt", nil
16 default:
17 return "", errors.New("unknown network")
18 }
19}
20func main() {
21 for _, n := range []string{"mainnet", "testnet3", "testnet4", "signet", "regtest"} {
22 v, _ := hrp(n)
23 fmt.Println(n, v)
24 }
25}Run locally
From the 001-foundations directory:
go test ./07-networks
go run ./07-networks
Regression test
1package main
2
3import (
4 "testing"
5)
6
7func TestExample(t *testing.T) {
8 for _, n := range []string{"testnet3", "testnet4", "signet"} {
9 v, e := hrp(n)
10 if e != nil || v != "tb" {
11 t.Fatal(n, v, e)
12 }
13 }
14 if _, e := hrp("unknown"); e == nil {
15 t.Fatal("unknown accepted")
16 }
17}Exercise
Compare testnet3 and signet prefixes and explain why a node identity check is necessary.
Reference
https://github.com/bitcoin/bips/blob/master/bip-0094.mediawiki
Series navigation
https://thamer.org/learn/bitcoin-development-libraries-go
Previous lesson:
https://thamer.org/learn/bitcoin-chain-parameters-go
Next lesson:
https://thamer.org/learn/first-bitcoin-development-toolkit-go
