Skip to content

Commit 7ce8869

Browse files
Merge pull request #1239 from dfinity/kristofer/fix_basic_bitcoin_readme
basic_bitcoin: Update TOC of Readme
2 parents 493345e + 9a81ae0 commit 7ce8869

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

rust/basic_bitcoin/README.md

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,85 @@
22

33
This example demonstrates how to deploy a smart contract on the Internet Computer that can receive and send bitcoin, including support for legacy (P2PKH), SegWit (P2WPKH), and Taproot (P2TR) address types.
44

5-
This example also includes examples of how to work with Bitcoin assets such as Ordinals, Runes, and BRC-20 tokens.
5+
This example also includes how to work with Bitcoin assets such as Ordinals, Runes, and BRC-20 tokens.
66

77
## Table of contents
88

9-
- [Architecture](#architecture)
10-
- [Prerequisites](#prerequisites)
11-
- [Building and deploying the smart contract](#building-and-deploying-the-smart-contract)
12-
- [Generating Bitcoin addresses](#generating-bitcoin-addresses)
13-
- [Receiving bitcoin](#receiving-bitcoin)
14-
- [Checking balance](#checking-balance)
15-
- [Sending bitcoin](#sending-bitcoin)
16-
- [Retrieving block headers](#retrieving-block-headers)
17-
- [Bitcoin assets](#bitcoin-assets)
18-
- [Inscribe an Ordinal](#inscribe-an-ordinal)
19-
- [Etch a Rune](#etch-a-rune)
20-
- [Deploy a BRC-20 token](#deploy-a-brc-20-token)
21-
- [Notes on implementation](#notes-on-implementation)
22-
- [Security considerations and best practices](#security-considerations-and-best-practices)
9+
* [Architecture](#architecture)
10+
* [Deploying from ICP Ninja](#deploying-from-icp-ninja)
11+
* [Building and deploying the smart contract locally](#building-and-deploying-the-smart-contract-locally)
12+
* [1. Prerequisites](#1-prerequisites)
13+
* [2. Clone the examples repo](#2-clone-the-examples-repo)
14+
* [3. Start the ICP execution environment](#3-start-the-icp-execution-environment)
15+
* [4. Start Bitcoin regtest](#4-start-bitcoin-regtest)
16+
* [5. Deploy the smart contract](#4-deploy-the-smart-contract)
17+
* [Generating Bitcoin addresses](#generating-bitcoin-addresses)
18+
* [Receiving bitcoin](#receiving-bitcoin)
19+
* [Prerequisites](#prerequisites)
20+
* [Checking balance](#checking-balance)
21+
* [Sending bitcoin](#sending-bitcoin)
22+
* [Retrieving block headers](#retrieving-block-headers)
23+
* [Bitcoin assets](#bitcoin-assets)
24+
25+
* [Prerequisites for Bitcoin assets](#prerequisites-for-bitcoin-assets)
26+
* [Inscribe an Ordinal](#inscribe-an-ordinal)
27+
* [Etch a Rune](#etch-a-rune)
28+
* [Deploy a BRC-20 token](#deploy-a-brc-20-token)
29+
* [Notes on implementation](#notes-on-implementation)
30+
* [Security considerations and best practices](#security-considerations-and-best-practices)
2331

2432
## Architecture
2533

2634
This example integrates with the Internet Computer's built-in:
2735

28-
- [ECDSA API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-ecdsa_public_key)
29-
- [Schnorr API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_schnorr)
30-
- [Bitcoin API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md)
36+
* [ECDSA API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-ecdsa_public_key)
37+
* [Schnorr API](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-sign_with_schnorr)
38+
* [Bitcoin API](https://github.com/dfinity/bitcoin-canister/blob/master/INTERFACE_SPECIFICATION.md)
3139

3240
For background on the ICP<>BTC integration, refer to the [Learn Hub](https://learn.internetcomputer.org/hc/en-us/articles/34211154520084-Bitcoin-Integration).
3341

34-
## Prerequisites
35-
36-
- [x] [Rust toolchain](https://www.rust-lang.org/tools/install)
37-
- [x] [Internet Computer SDK](https://internetcomputer.org/docs/building-apps/getting-started/install)
38-
- [x] [Local Bitcoin testnet (regtest)](https://internetcomputer.org/docs/build-on-btc/btc-dev-env#create-a-local-bitcoin-testnet-regtest-with-bitcoind)
39-
- [x] On macOS, an `llvm` version that supports the `wasm32-unknown-unknown` target is required. This is because the Rust `bitcoin` library relies on the `secp256k1-sys` crate, which requires `llvm` to build. The default `llvm` version provided by XCode does not meet this requirement. Instead, install the [Homebrew version](https://formulae.brew.sh/formula/llvm), using `brew install llvm`.
4042

4143
## Deploying from ICP Ninja
4244

43-
This example can be deployed directly to the Internet Computer using ICP Ninja, where it will connect to Bitcoin **testnet4**. Note: Canisters deployed using ICP Ninja remain live for 50 minutes after signing in with your Internet Identity (accessible via the top-right button in ICP Ninja).
45+
This example can be deployed directly to the Internet Computer using ICP Ninja, where it connects to Bitcoin **testnet4**. Note: Canisters deployed via ICP Ninja remain live for 50 minutes after signing in with your Internet Identity.
4446

4547
[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/basic_bitcoin)
4648

4749
## Building and deploying the smart contract locally
4850

49-
### 1. Clone the examples repo
51+
### 1. Prerequisites
52+
53+
* [x] [Rust toolchain](https://www.rust-lang.org/tools/install)
54+
* [x] [Internet Computer SDK](https://internetcomputer.org/docs/building-apps/getting-started/install)
55+
* [x] [Local Bitcoin testnet (regtest)](https://internetcomputer.org/docs/build-on-btc/btc-dev-env#create-a-local-bitcoin-testnet-regtest-with-bitcoind)
56+
* [x] On macOS, an `llvm` version that supports the `wasm32-unknown-unknown` target is required. The Rust `bitcoin` library relies on the `secp256k1-sys` crate, which requires `llvm` to build. The default `llvm` version provided by XCode does not meet this requirement. Install the [Homebrew version](https://formulae.brew.sh/formula/llvm) using `brew install llvm`.
57+
58+
59+
### 2. Clone the examples repo
5060

5161
```bash
5262
git clone https://github.com/dfinity/examples
5363
cd examples/rust/basic_bitcoin
5464
```
5565

56-
### 2. Start the ICP execution environment
66+
### 3. Start the ICP execution environment
67+
5768

5869
Open a terminal window (terminal 1) and run the following:
5970
```bash
6071
dfx start --enable-bitcoin --bitcoin-node 127.0.0.1:18444
6172
```
6273
This starts a local canister execution environment with Bitcoin support enabled.
6374

64-
### 3. Start Bitcoin regtest
75+
### 4. Start Bitcoin regtest
6576

6677
Open another terminal window (terminal 2) and run the following to start the local Bitcoin regtest network:
6778

6879
```bash
6980
bitcoind -conf=$(pwd)/bitcoin.conf -datadir=$(pwd)/bitcoin_data --port=18444
7081
```
7182

72-
### 4. Deploy the smart contract
83+
### 5. Deploy the smart contract
7384

7485
Open a third terminal (terminal 3) and run the following to deploy the smart contract:
7586

@@ -83,7 +94,6 @@ What this does:
8394
- `--argument '(variant { regtest })'` passes the argument `regtest` to initialize the smart contract, telling it to connect to the local Bitcoin regtest network.
8495

8596
Your smart contract is live and ready to use! You can interact with it using either the command line or the Candid UI (the link you see in the terminal).
86-
8797
## Generating Bitcoin addresses
8898

8999
The example demonstrates how to generate and use the following address types:
@@ -92,35 +102,32 @@ The example demonstrates how to generate and use the following address types:
92102
2. **P2WPKH (SegWit v0)** using ECDSA and `sign_with_ecdsa`
93103
3. **P2TR (Taproot, key-path-only)** using Schnorr keys and `sign_with_schnorr`
94104
4. **P2TR (Taproot, script-path-enabled)** commits to a script allowing both key path and script path spending
95-
96-
Use the Candid UI or command line to generate these addresses with:
105+
Use the Candid UI or CLI to generate:
97106

98107
```bash
99108
dfx canister call basic_bitcoin get_p2pkh_address
100-
# or get_p2wpkh_address, get_p2tr_key_path_only_address, get_p2tr_script_path_enabled_address
109+
# or: get_p2wpkh_address, get_p2tr_key_path_only_address, get_p2tr_script_path_enabled_address
101110
```
102111

103112
## Receiving bitcoin
104113

105114
Use the `bitcoin-cli` to mine a Bitcoin block and send the block reward in the form of local testnet bitcoin to one of the smart contract addresses.
106-
107115
```bash
108116
bitcoin-cli -conf=$(pwd)/bitcoin.conf generatetoaddress 1 <bitcoin_address>
109117
```
110118

111119
## Checking balance
112120

113121
Check the balance of any Bitcoin address:
114-
115122
```bash
116123
dfx canister call basic_bitcoin get_balance '("<bitcoin_address>")'
117124
```
118125

119126
This uses `bitcoin_get_balance` and works for any supported address type. The balance requires at least one confirmation to be reflected.
120-
121127
## Sending bitcoin
122128

123129
You can send bitcoin using the following endpoints:
130+
Endpoints:
124131

125132
- `send_from_p2pkh_address`
126133
- `send_from_p2wpkh_address`
@@ -165,7 +172,6 @@ dfx canister call basic_bitcoin get_block_headers '(10: nat32, opt (11: nat32))'
165172
```
166173
167174
This calls `bitcoin_get_block_headers`, which is useful for blockchain validation or light client logic.
168-
169175
## Bitcoin assets
170176

171177
Bitcoin's scripting capabilities enable various digital assets beyond simple transfers. This example demonstrates how to create and interact with three major Bitcoin asset protocols from an ICP smart contract:
@@ -307,7 +313,6 @@ The deployment inscription contains JSON metadata that BRC-20 indexers use to tr
307313

308314
To view the deployed BRC-20 token, use the local `ord` explorer at `http://127.0.0.1:80/`.
309315

310-
311316
## Notes on implementation
312317

313318
This example implements several important patterns for Bitcoin integration:
@@ -331,4 +336,4 @@ For example, the following aspects are particularly relevant for this app:
331336

332337
---
333338

334-
_Last updated: June 2025_
339+
*Last updated: July 2025*

0 commit comments

Comments
 (0)