# 学习比特币

Original: <https://lifelonglearn.ing/learn-bitcoin>

Author: [奶爸](https://lifelonglearn.ing/users/3b04650c-8231-499b-8ef0-381fc4d7efb0)

Published: 2022-08-30T11:15:16Z

Updated: 2026-09-27T06:57:43Z

Version: 1

公司的钱包 App 要在 Ethereum 基础上增加 Bitcoin 支持，记录下学习过程，今天下午之前我对 **₿** 知之甚少，本文假设你已对 [Go](https://lifelonglearn.ing/tags/Go/) 和 [Rust](https://lifelonglearn.ing/tags/Rust/) 有一定了解。

## 开发者工具

* [Bitcoin 测试网水龙头](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9iaXRjb2luZmF1Y2V0LnVvMS5uZXQv)
* [rust-bitcoin](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9kb2NzLnJzL2JpdGNvaW4=)：rust 库
  * [该库 wallet 实现](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9naXRodWIuY29tL3J1c3QtYml0Y29pbi9ydXN0LXdhbGxldA==)
  * [Address Relevant BIPs](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9kb2NzLnJzL2JpdGNvaW4vMC4yOS4xL2JpdGNvaW4vdXRpbC9hZGRyZXNzL3N0cnVjdC5BZGRyZXNzLmh0bWwjcmVsZXZhbnQtYmlwcw==)
* [bitcore-lib](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9naXRodWIuY29tL2JpdHBheS9iaXRjb3JlL3RyZWUvbWFzdGVyL3BhY2thZ2VzL2JpdGNvcmUtbGli)：JavaScript 库
  * 有一些 [Example](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9naXRodWIuY29tL2JpdHBheS9iaXRjb3JlL3RyZWUvbWFzdGVyL3BhY2thZ2VzL2JpdGNvcmUtbGliI2V4YW1wbGVz)
* Electrum
  * 开源实现
    * Rust: [https://github.com/romanz/electrs](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9naXRodWIuY29tL3JvbWFuei9lbGVjdHJz)
    * Python: [https://github.com/spesmilo/electrumx](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9naXRodWIuY29tL3NwZXNtaWxvL2VsZWN0cnVteA==)
  * [公开服务器列表](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly8xMjA5ay5jb20vYml0Y29pbi1leWUvZWxlLnBocA==)：找到 ElectrumX 的公开服务器
  * 与 ElectrumX 交互（取 UTXO 列表）
    ```shell
    electrum-cli --server ru.poiuty.com:50002 blockchain.scripthash.listunspent 8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161
    ```
* [Broadcast & Preview Transaction](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly90YnRjLmJpdGFwcy5jb20vYnJvYWRjYXN0)

## 相关文献

### Address

* [List of address prefixes](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9lbi5iaXRjb2luLml0L3dpa2kvTGlzdF9vZl9hZGRyZXNzX3ByZWZpeGVz)
* P2SH
  * [图解 P2SH](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9sZWFybm1lYWJpdGNvaW4uY29tL3RlY2huaWNhbC9wMnNo)
  * [Python 验证 P2SH locking script && unlocking script 实例](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9iaXRjb2luLnN0YWNrZXhjaGFuZ2UuY29tL3F1ZXN0aW9ucy83NTUyOC9wMnNoLXNpZ25hdHVyZS12ZXJpZmljYXRpb24taW4tcHl0aG9u)
* P2SH-P2WPKH
  * [详解](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9iaXRjb2luY29yZS5vcmcvZW4vc2Vnd2l0X3dhbGxldF9kZXYv)
    * [P2SH-P2WPKH Unlocking script](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9tZWRpdW0uY29tL0BhY2tob3IvMTAtNi1zb21ldGhpbmctb24tcDJzaC1wMndwa2gtdW5sb2NraW5nLWxvY2tpbmctc2NyaXB0LTYzNTJkZjBiNThmMQ==)
* [Bitcoin address generator](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9raW1iYXR0LmdpdGh1Yi5pby9idGMtYWRkcmVzcy1nZW5lcmF0b3IvP3Rlc3RuZXQ=)：BTC 地址生成
* [从 address 计算 scripthash](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9naXRodWIuY29tL3NwZXNtaWxvL2VsZWN0cnVteC9pc3N1ZXMvMzI=)：用于跟 Electrum 节点交互
* [重用地址](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9lbi5iaXRjb2luLml0L3dpa2kvQWRkcmVzc19yZXVzZQ==) 的危害

### Transaction

* [Bitcoins the hard way: Using the raw Bitcoin protocol](https://lifelonglearn.ing/r/go?url=aHR0cDovL3d3dy5yaWdodG8uY29tLzIwMTQvMDIvYml0Y29pbnMtaGFyZC13YXktdXNpbmctcmF3LWJpdGNvaW4uaHRtbA==)：学习 Bitcoin 底层协议
  * [Hashtype 的含义](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9lbi5iaXRjb2luLml0L3dpa2kvT1BfQ0hFQ0tTSUc=)
* [使用 Go 发起比特币交易并签名](https://lifelonglearn.ing/r/go?url=aHR0cHM6Ly9tZWRpdW0uY29tL3N3bGgvY3JlYXRlLXJhdy1iaXRjb2luLXRyYW5zYWN0aW9uLWFuZC1zaWduLWl0LXdpdGgtZ29sYW5nLTk2YjVlMTBjMzBhYQ==)：这篇文章里面讲了生成一个私钥（钱包），然后派生出地址来，然后 transaction 的格式，还有一些其他的基础知识。
  * fee: sum(input.value) -> sum(output.value)
